aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-02-03 03:18:25 -0500
committerB. Watson <urchlay@slackware.uk>2025-02-03 03:18:25 -0500
commit489370d1500383f3b2760a50637f11a817870004 (patch)
tree4e97ad3ba82e13206aa75ff20334b9fe0e6cb464
parent3a87634357407be554f32880d9a6600d2db55431 (diff)
downloadmisc-scripts-489370d1500383f3b2760a50637f11a817870004.tar.gz
bsgrep: use utf-8 when in utf-8 locale.
-rwxr-xr-xbsgrep9
1 files changed, 9 insertions, 0 deletions
diff --git a/bsgrep b/bsgrep
index 26f247e..d4ef311 100755
--- a/bsgrep
+++ b/bsgrep
@@ -73,6 +73,15 @@ sub handle_line {
}
### main()
+# TODO: do we need 'use locale'?
+# also, why does reading iso-8859-1 text auto-convert to utf-8?
+for (qw/LANG LC_CTYPE LC_ALL/) {
+ if(($ENV{$_} // "") =~ /utf-?8/i) {
+ binmode(\*STDIN, ':utf8');
+ binmode(\*STDOUT, ':utf8');
+ last;
+ }
+}
if(defined($ARGV[0])) {
if($ARGV[0] =~ /-help/) {