+if [[ -n $ZSH_PROFILE_RC ]] ; then
+ zmodload zsh/zprof
+fi
+# }}}
+
+# utility functions {{{
+# this function checks if a command exists and returns either true
+# or false. This avoids using 'which' and 'whence', which will
+# avoid problems with aliases for which on certain weird systems. :-)
+check_com() {
+ local -i comonly
+
+ if [[ ${1} == '-c' ]] ; then
+ (( comonly = 1 ))
+ shift
+ else
+ (( comonly = 0 ))
+ fi
+
+ if (( ${#argv} != 1 )) ; then
+ printf 'usage: check_com [-c] <command>\n' >&2
+ return 1
+ fi
+
+ if (( comonly > 0 )) ; then
+ [[ -n ${commands[$1]} ]] && return 0
+ return 1
+ fi
+
+ if [[ -n ${commands[$1]} ]] \
+ || [[ -n ${functions[$1]} ]] \
+ || [[ -n ${aliases[$1]} ]] \
+ || [[ -n ${reswords[(r)$1]} ]] ; then
+
+ return 0
+ fi
+
+ return 1
+}
+
+# creates an alias and precedes the command with
+# sudo if $EUID is not zero.
+salias() {
+ local only=0 ; local multi=0
+ while [[ ${1} == -* ]] ; do
+ case ${1} in
+ (-o) only=1 ;;
+ (-a) multi=1 ;;
+ (--) shift ; break ;;
+ (-h)
+ printf 'usage: salias [-h|-o|-a] <alias-expression>\n'
+ printf ' -h shows this help text.\n'
+ printf ' -a replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n'
+ printf ' be careful using this option.\n'
+ printf ' -o only sets an alias if a preceding sudo would be needed.\n'
+ return 0
+ ;;
+ (*) printf "unkown option: '%s'\n" "${1}" ; return 1 ;;
+ esac
+ shift
+ done
+
+ if (( ${#argv} > 1 )) ; then
+ printf 'Too many arguments %s\n' "${#argv}"
+ return 1
+ fi
+
+ key="${1%%\=*}" ; val="${1#*\=}"
+ if (( EUID == 0 )) && (( only == 0 )); then
+ alias -- "${key}=${val}"
+ elif (( EUID > 0 )) ; then
+ (( multi > 0 )) && val="${val// ; / ; sudo }"
+ alias -- "${key}=sudo ${val}"
+ fi
+
+ return 0
+}
+
+# Check if we can read given files and source those we can.
+xsource() {
+ if (( ${#argv} < 1 )) ; then
+ printf 'usage: xsource FILE(s)...\n' >&2
+ return 1
+ fi
+
+ while (( ${#argv} > 0 )) ; do
+ [[ -r ${1} ]] && source ${1}
+ shift
+ done
+ return 0
+}
+
+# Check if we can read a given file and 'cat(1)' it.
+xcat() {
+ if (( ${#argv} != 1 )) ; then
+ printf 'usage: xcat FILE\n' >&2
+ return 1
+ fi
+
+ [[ -r ${1} ]] && cat ${1}
+ return 0
+}
+
+# Remove these functions again, they are of use only in these
+# setup files. This should be called at the end of .zshrc.
+xunfunction() {
+ local -a funcs
+ funcs=(check_com salias xcat xsource xunfunction)
+
+ for func in $funcs ; do
+ [[ -n ${functions[$func]} ]] \
+ && unfunction $func
+ done
+ return 0
+}
+#}}}
+
+# locale setup {{{
+if [[ -z "$LANG" ]] ; then
+ xsource "/etc/default/locale"
+fi
+
+export LANG=${LANG:-en_US.iso885915}
+for var in LC_ALL LC_MESSAGES ; do
+ [[ -n ${(P)var} ]] && export $var
+done
+
+xsource "/etc/sysconfig/keyboard"
+
+TZ=$(xcat /etc/timezone)
+# }}}
+
+# check for potentially old files in 'completion.d' {{{
+setopt extendedglob
+xof=(/etc/zsh/completion.d/*~/etc/zsh/completion.d/_*(N))
+if (( ${#xof} > 0 )) ; then
+ printf '\n -!- INFORMATION\n\n'
+ printf ' -!- %s file(s) not starting with an underscore (_) found in\n' ${#xof}
+ printf ' -!- /etc/zsh/completion.d/.\n\n'
+ printf ' -!- While this has been the case in old versions of grml-etc-core,\n'
+ printf ' -!- recent versions of the grml-zsh-setup have all these files rewritten\n'
+ printf ' -!- and renamed. Furthermore, the grml-zsh-setup will *only* add files\n'
+ printf ' -!- named _* to that directory.\n\n'
+ printf ' -!- If you added functions to completion.d yourself, please consider\n'
+ printf ' -!- moving them to /etc/zsh/functions.d/. Files in that directory, not\n'
+ printf ' -!- starting with an underscore are marked for automatic loading\n'
+ printf ' -!- by default (so that is quite convenient).\n\n'
+ printf ' -!- If there are files *not* starting with an underscore from an older\n'
+ printf ' -!- grml-etc-core in completion.d, you may safely remove them.\n\n'
+ printf ' -!- Delete the files for example via running:\n\n'
+ printf " rm ${xof}\n\n"
+ printf ' -!- Note, that this message will *not* go away, unless you yourself\n'
+ printf ' -!- resolve the situation manually.\n\n'
+ BROKEN_COMPLETION_DIR=1
+fi
+unset xof