Updated patch, really filters out commented lines. I'm thinking whether we want to make it a conffile, so local administrator can override it themselves, what do you think?
Thanks, Aron
From 5fb66297a70e4afcfcb1c9893fc8e660da397aaf Mon Sep 17 00:00:00 2001 From: Aron Xu <a...@debian.org> Date: Fri, 13 Mar 2015 04:25:58 +0800 Subject: [PATCH] Add the ability to set preferred auto IM by locale Users of different locales may have their preferred default IM, this adds the ability of setting an IM that's preferred when "auto" is selected (which is the default), managed by locale. --- share/locale_prefs | 7 +++++++ share/xinputrc.common.in | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 share/locale_prefs.conf Index: im-config-0.27/share/xinputrc.common.in =================================================================== --- im-config-0.27.orig/share/xinputrc.common.in +++ im-config-0.27/share/xinputrc.common.in @@ -8,6 +8,7 @@ ############################################################# IM_CONFIG_VERSION=@@VERSION@@ IM_CONFIG_DATA=/usr/share/im-config/data +IM_CONFIG_LC_PREFS=/usr/share/im-config/locale_prefs IM_CONFIG_XINPUTRC_USR=$HOME/.xinputrc IM_CONFIG_XINPUTRC_SYS=/etc/X11/xinit/xinputrc IM_CONFIG_DEFAULT=/etc/default/im-config @@ -86,7 +87,16 @@ avail_auto () { # automatic_im # echo automatic IM configuration name automatic_im () { -# auto mode uses first available script in 10-79 +# locale preference handling, takes precedence if valid + if [ -r $IM_CONFIG_LC_PREFS ]; then + IM_CONFIG_LC_CTYPE=$(locale | sed -nr 's/LC_CTYPE=\"([a-zA-Z_]*).*\"/\1/p') + IM_CONFIG_SCRIPT=$(grep $IM_CONFIG_LC_CTYPE $IM_CONFIG_LC_PREFS | grep -v '^#' | awk '{print $2}') + if [ "$IM_CONFIG_SCRIPT" != "" ] && avail_auto $IM_CONFIG_SCRIPT ; then + echo -n "$IM_CONFIG_SCRIPT" + return + fi + fi +# otherwise auto mode uses first available script in 10-79 # 79 is for "none", i.e., no IM used for IM_CONFIG_SCRIPT_PATH in $IM_CONFIG_DATA/[1234567]*.rc ; do IM_CONFIG_SCRIPT=$(name_im $IM_CONFIG_SCRIPT_PATH) Index: im-config-0.27/share/locale_prefs =================================================================== --- /dev/null +++ im-config-0.27/share/locale_prefs @@ -0,0 +1,7 @@ +# Preferred IM for "auto" by locale +# +# Syntax: +# 1) Each line shall contain an ordered pair of values separated by space: +# locale name and preferred IM name; +# 2) Add multiple lines for as many locales as desired; +# 3) Lines begin with a hash sign ("#") are ignored.