+# zsh-refcard-tag documentation: {{{
+# You may notice strange looking comments in the zshrc (and ~/.zshrc as
+# well). These are there for a purpose. grml's zsh-refcard can now be
+# automatically generated from the contents of the actual configuration
+# files. However, we need a little extra information on which comments
+# and what lines of code to take into account (and for what purpose).
+#
+# Here is what they mean:
+#
+# List of tags (comment types) used:
+# #a# Next line contains an important alias, that should
+# be included in the grml-zsh-refcard.
+# (placement tag: @@INSERT-aliases@@)
+# #f# Next line contains the beginning of an important function.
+# (placement tag: @@INSERT-functions@@)
+# #v# Next line contains an important variable.
+# (placement tag: @@INSERT-variables@@)
+# #k# Next line contains an important keybinding.
+# (placement tag: @@INSERT-keybindings@@)
+# #d# Hashed directories list generation:
+# start denotes the start of a list of 'hash -d'
+# definitions.
+# end denotes its end.
+# (placement tag: @@INSERT-hasheddirs@@)
+# #A# Abbreviation expansion list generation:
+# start denotes the beginning of abbreviations.
+# end denotes their end.
+# Lines within this section that end in '#d .*' provide
+# extra documentation to be included in the refcard.
+# (placement tag: @@INSERT-abbrev@@)
+# #m# This tag allows you to manually generate refcard entries
+# for code lines that are hard/impossible to parse.
+# Example:
+# #m# k ESC-h Call the run-help function
+# That would add a refcard entry in the keybindings table
+# for 'ESC-h' with the given comment.
+# So the syntax is: #m# <section> <argument> <comment>
+# #o# This tag lets you insert entries to the 'other' hash.
+# Generally, this should not be used. It is there for
+# things that cannot be done easily in another way.
+# (placement tag: @@INSERT-other-foobar@@)
+#
+# All of these tags (except for m and o) take two arguments, the first
+# within the tag, the other after the tag:
+#
+# #<tag><section># <comment>
+#
+# Where <section> is really just a number, which are defined by the
+# @secmap array on top of 'genrefcard.pl'. The reason for numbers
+# instead of names is, that for the reader, the tag should not differ
+# much from a regular comment. For zsh, it is a regular comment indeed.
+# The numbers have got the following meanings:
+# 0 -> "default"
+# 1 -> "system"
+# 2 -> "user"
+# 3 -> "debian"
+# 4 -> "search"
+# 5 -> "shortcuts"
+# 6 -> "services"
+#
+# So, the following will add an entry to the 'functions' table in the
+# 'system' section, with a (hopefully) descriptive comment:
+# #f1# Edit an alias via zle
+# edalias() {
+#
+# It will then show up in the @@INSERT-aliases-system@@ replacement tag
+# that can be found in 'grml-zsh-refcard.tex.in'.
+# If the section number is omitted, the 'default' section is assumed.
+# Furthermore, in 'grml-zsh-refcard.tex.in' @@INSERT-aliases@@ is
+# exactly the same as @@INSERT-aliases-default@@. If you want a list of
+# *all* aliases, for example, use @@INSERT-aliases-all@@.
+#}}}
+
+# zsh profiling {{{
+# just execute 'ZSH_PROFILE_RC=1 zsh' and run 'zprof' to get the details
+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[$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
+# }}}
+