On Thu, Dec 18, 2003 at 01:38:35PM +0000, Colin Watson wrote: > On Thu, Dec 18, 2003 at 10:12:13AM +0100, Sven Luther wrote: > > Other problems is sshing from a non UTF terminal, but then luit helps, > > but there is not really much we can do there, no ?
> This is a pain in the arse, frankly, because there's no way I've found > to pass environment variables such as LANG across the ssh connection. If > anyone knows of a not-too-hacky way to do this, I'd be interested. A colleague of mine wrote the attached Perl script to detect UTF-8 (the only real language setting he, and I, want to transparently inherit over SSH (and other) connections is LC_CTYPE, anyway.) Place it somewhere, and call it from your .bashrc with something like: if [ -n "$PS1" ]; then eval `detect-utf8-term` fi You'll have to fiddle the script itself to use it with tcsh, but not in any spectacular way. It needs Term::ReadKey (libterm-readkey-perl). It only sets LC_CTYPE, and it sets it hardcoded to en_US.UTF-8 when it detects UTF-8. It also eats all typeahead, unfortunately, which may be annoying depending on your habits. -- Thomas Wouters <[EMAIL PROTECTED]> Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
#!/usr/bin/perl -w # Written by Jan-Pieter Cornet <[EMAIL PROTECTED]>, # released to the public domain. If you break it, you get to keep both pieces. use strict; use Term::ReadKey; use bytes; my $lc_ctype = $ENV{LC_CTYPE} || $ENV{LC_ALL} || $ENV{LANG}; if ( defined($lc_ctype) && $lc_ctype =~ /utf-?8/i ) { ### uncomment me if you want silly messages in normal xterms #print STDERR "Already UTF-8 enabled\n"; exit; } ReadMode 'cbreak'; ### Send CR, test sequence that's valid ISO8859-1 and valid UTF8, and ### cursor reporting escape ^[[6n. print STDERR "\r", chr 0xC2, chr 0xA4, chr 27, '[6n'; ### read response from terminal, usually ^[[#;#R my $r = ''; while ( my $c = ReadKey 0.1 ) { $r .= $c; last if $c eq 'R'; } ReadMode 'restore'; ### parse returned string my($x) = $r =~ /^\x1B\[\d+;(\d+)R$/; if ( !defined $x ) { print STDERR "Couldn't parse return: ", ( map { sprintf "%02x ", ord } split //, $r ), "\n"; } elsif ( $x == 2 ) { ### It's UTF-8 enabled, search for a valid locale my @locales = `locale -a`; my($utflocale) = grep /utf-?8/i, @locales; ### sensible default...? $utflocale ||= 'en_US.UTF-8'; print STDERR "\r \r"; print "export LC_CTYPE=$utflocale\n"; } elsif ( $x == 3 ) { ### it's standard ISO8859 print STDERR "\r \r"; } else { ### dunno? print STDERR "Strange x-coord after test: $x\n"; }