oh-my-zsh/lib/misc.zsh
Vincent Bernat 4e02a284eb 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, ...).
2015-12-15 07:58:59 +01:00

54 lines
1.2 KiB
Bash

## Load smart urls if available
# bracketed-paste-magic is known buggy in zsh 5.1.1 (only), so skip it there; see #4434
autoload -Uz is-at-least
if [[ $ZSH_VERSION != 5.1.1 ]]; then
for d in $fpath; do
if [[ -e "$d/url-quote-magic" ]]; then
if is-at-least 5.1; then
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
fi
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
break
fi
done
fi
## jobs
setopt long_list_jobs
## pager
export PAGER="less"
export LESS="-R"
## super user alias
alias _='sudo'
alias please='sudo'
## more intelligent acking for ubuntu users
if which ack-grep &> /dev/null; then
alias afind='ack-grep -il'
else
alias afind='ack -il'
fi
# only define LC_CTYPE if undefined
LC_CTYPE=${LC_CTYPE:-${LC_ALL:-${LANG:-C}}}
case $LC_CTYPE in
*.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
setopt interactivecomments