Ensure LC_CTYPE uses UTF-8
See #2012 for some context. Many unicode-related tasks need that coaelescing to handle unicode correctly. If for some reason, the user is using a not using a non-unicode locale, we want to ensure that at least LC_CTYPE is set to an unicode locale. It's difficult to know if a locale is an unicode one, so we assume that we want UTF-8 as an unicode codec. Aliases are not handled, so LC_CTYPE may be redefined even if it was already unicode aware. The first available UTF-8 locale is used because there is no guarantee that C.UTF-8 or en_US.UTF-8 are available. For LC_CTYPE, there is no difference between those locales as coaelescing is not dependant on the language. LC_CTYPE is exported as oh-my-zsh may use some shell tools at some point (sed, awk, ...).
This commit is contained in:
parent
5de1704a0a
commit
4e02a284eb
17
lib/misc.zsh
17
lib/misc.zsh
@ -34,9 +34,20 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# only define LC_CTYPE if undefined
|
# only define LC_CTYPE if undefined
|
||||||
if [[ -z "$LC_CTYPE" && -z "$LC_ALL" ]]; then
|
LC_CTYPE=${LC_CTYPE:-${LC_ALL:-${LANG:-C}}}
|
||||||
export LC_CTYPE=${LANG%%:*} # pick the first entry from LANG
|
case $LC_CTYPE in
|
||||||
fi
|
*.utf8|*.UTF-8)
|
||||||
|
# All is correct
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Need to select an UTF-8 locale
|
||||||
|
local -a available
|
||||||
|
available=("${(f)$(locale -a 2> /dev/null)}")
|
||||||
|
export LC_CTYPE=${${${${(@M)available:#*.UTF-8}[1]}:-${${(@M)available:#*.utf8}[1]}}:-C.UTF-8}
|
||||||
|
unset available
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
export LC_CTYPE
|
||||||
|
|
||||||
# recognize comments
|
# recognize comments
|
||||||
setopt interactivecomments
|
setopt interactivecomments
|
||||||
|
Loading…
Reference in New Issue
Block a user