bash_profile: Slightly more intelligent locale handling.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 26 Mar 2009 16:30:29 +0000 (16:30 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 26 Mar 2009 16:50:42 +0000 (16:50 +0000)
First of all, set LANG and LC_COLLATE and leave the rest alone.  LANG
defaults most of the other variables, and forcing LC_COLLATE=POSIX fixes
the stupidity of ls(1) ordering things case-insensitively.

Secondly, if there's no DISPLAY, and TERM is `linux', prod vt-is-UTF8(1)
to find out which locale to use.

bash_profile

index 57475a8..7488133 100644 (file)
@@ -112,18 +112,23 @@ umask 002
 
 [ -z "$HOST" ] && export HOST=`hostname`
 
-if [ "$DISPLAY" = "" ]; then
-  : ${LC_CTYPE=${LANG-${LC_ALL-`mdw-conf console-ctype`}}}
+if [ "$DISPLAY" != "" ]; then
+  LANG=`mdw-conf x-ctype`
 else
-  LC_CTYPE=`mdw-conf x-ctype`
+  : ${LANG=${LC_CTYPE-${LC_ALL-`mdw-conf console-ctype`}}}
+  case "$TERM" in
+    linux)
+      if vt-is-UTF8 >/dev/null 2>&1; then
+       ctype=.utf8
+      else
+       ctype=
+      fi
+      LANG=${LANG%.*}$ctype
+      ;;
+  esac
 fi
-unset LANG LC_ALL
-export LC_CTYPE
-
-for lc in TIME NUMERIC MONETARY PAPER NAME ADDRESS TELEPHONE MEASUREMENT; do
-  eval "export LC_$lc=$LC_CTYPE"
-done
-export LC_COLLATE=POSIX
+unset LC_ALL
+export LC_COLLATE=POSIX LANG
 
 __mdw_programp distcc && export CCACHE_PREFIX=distcc