+typeset -A GRML_STATUS_FEATURES
+
+function grml_status_feature () {
+ emulate -L zsh
+ local f=$1
+ local -i success=$2
+ if (( success == 0 )); then
+ GRML_STATUS_FEATURES[$f]=success
+ else
+ GRML_STATUS_FEATURES[$f]=failure
+ fi
+ return 0
+}
+
+function grml_status_features () {
+ emulate -L zsh
+ local mode=${1:-+-}
+ local this
+ if [[ $mode == -h ]] || [[ $mode == --help ]]; then
+ cat <<EOF
+grml_status_features [-h|--help|-|+|+-|FEATURE]
+
+Prints a summary of features the grml setup is trying to load. The
+result of loading a feature is recorded. This function lets you query
+the result.
+
+The function takes one argument: "-h" or "--help" to display this help
+text, "+" to display a list of all successfully loaded features, "-" for
+a list of all features that failed to load. "+-" to show a list of all
+features with their statuses.
+
+Any other word is considered to by a feature and prints its status.
+
+The default mode is "+-".
+EOF
+ return 0
+ fi
+ if [[ $mode != - ]] && [[ $mode != + ]] && [[ $mode != +- ]]; then
+ this="${GRML_STATUS_FEATURES[$mode]}"
+ if [[ -z $this ]]; then
+ printf 'unknown\n'
+ return 1
+ else
+ printf '%s\n' $this
+ fi
+ return 0
+ fi
+ for key in ${(ok)GRML_STATUS_FEATURES}; do
+ this="${GRML_STATUS_FEATURES[$key]}"
+ if [[ $this == success ]] && [[ $mode == *+* ]]; then
+ printf '%-16s %s\n' $key $this
+ fi
+ if [[ $this == failure ]] && [[ $mode == *-* ]]; then
+ printf '%-16s %s\n' $key $this
+ fi
+ done
+ return 0
+}
+
+# load .zshrc.pre to give the user the chance to overwrite the defaults
+[[ -r ${ZDOTDIR:-${HOME}}/.zshrc.pre ]] && source ${ZDOTDIR:-${HOME}}/.zshrc.pre
+
+# check for version/system
+# check for versions (compatibility reasons)
+function is51 () {
+ [[ $ZSH_VERSION == 5.<1->* ]] && return 0
+ return 1
+}
+
+function is4 () {
+ [[ $ZSH_VERSION == <4->* ]] && return 0
+ return 1
+}
+
+function is41 () {
+ [[ $ZSH_VERSION == 4.<1->* || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+function is42 () {
+ [[ $ZSH_VERSION == 4.<2->* || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+function is425 () {
+ [[ $ZSH_VERSION == 4.2.<5->* || $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+function is43 () {
+ [[ $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+function is433 () {
+ [[ $ZSH_VERSION == 4.3.<3->* || $ZSH_VERSION == 4.<4->* \
+ || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+function is437 () {
+ [[ $ZSH_VERSION == 4.3.<7->* || $ZSH_VERSION == 4.<4->* \
+ || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+function is439 () {
+ [[ $ZSH_VERSION == 4.3.<9->* || $ZSH_VERSION == 4.<4->* \
+ || $ZSH_VERSION == <5->* ]] && return 0
+ return 1
+}
+
+#f1# Checks whether or not you're running grml
+function isgrml () {
+ [[ -f /etc/grml_version ]] && return 0
+ return 1
+}
+
+#f1# Checks whether or not you're running a grml cd
+function isgrmlcd () {
+ [[ -f /etc/grml_cd ]] && return 0
+ return 1
+}
+
+if isgrml ; then
+#f1# Checks whether or not you're running grml-small
+ function isgrmlsmall () {
+ if [[ ${${${(f)"$(</etc/grml_version)"}%% *}##*-} == 'small' ]]; then
+ return 0
+ fi
+ return 1
+ }
+else
+ function isgrmlsmall () { return 1 }
+fi
+
+GRML_OSTYPE=$(uname -s)
+
+function islinux () {
+ [[ $GRML_OSTYPE == "Linux" ]]
+}
+
+function isdarwin () {
+ [[ $GRML_OSTYPE == "Darwin" ]]
+}
+
+function isfreebsd () {
+ [[ $GRML_OSTYPE == "FreeBSD" ]]
+}
+
+function isopenbsd () {
+ [[ $GRML_OSTYPE == "OpenBSD" ]]
+}
+
+function issolaris () {
+ [[ $GRML_OSTYPE == "SunOS" ]]
+}
+
+#f1# are we running within an utf environment?
+function isutfenv () {
+ case "$LANG $CHARSET $LANGUAGE" in
+ *utf*) return 0 ;;
+ *UTF*) return 0 ;;
+ *) return 1 ;;
+ esac
+}
+
+# check for user, if not running as root set $SUDO to sudo
+(( EUID != 0 )) && SUDO='sudo' || SUDO=''
+
+# change directory to home on first invocation of zsh
+# important for rungetty -> autologin
+# Thanks go to Bart Schaefer!
+isgrml && function checkhome () {
+ if [[ -z "$ALREADY_DID_CD_HOME" ]] ; then
+ export ALREADY_DID_CD_HOME=$HOME
+ cd
+ fi
+}
+
+# check for zsh v3.1.7+
+
+if ! [[ ${ZSH_VERSION} == 3.1.<7->* \
+ || ${ZSH_VERSION} == 3.<2->.<->* \
+ || ${ZSH_VERSION} == <4->.<->* ]] ; then
+
+ printf '-!-\n'
+ printf '-!- In this configuration we try to make use of features, that only\n'
+ printf '-!- require version 3.1.7 of the shell; That way this setup can be\n'
+ printf '-!- used with a wide range of zsh versions, while using fairly\n'
+ printf '-!- advanced features in all supported versions.\n'
+ printf '-!-\n'
+ printf '-!- However, you are running zsh version %s.\n' "$ZSH_VERSION"
+ printf '-!-\n'
+ printf '-!- While this *may* work, it might as well fail.\n'
+ printf '-!- Please consider updating to at least version 3.1.7 of zsh.\n'
+ printf '-!-\n'
+ printf '-!- DO NOT EXPECT THIS TO WORK FLAWLESSLY!\n'
+ printf '-!- If it does today, you'\''ve been lucky.\n'
+ printf '-!-\n'
+ printf '-!- Ye been warned!\n'
+ printf '-!-\n'
+
+ function zstyle () { : }
+fi
+
+# autoload wrapper - use this one instead of autoload directly
+# We need to define this function as early as this, because autoloading
+# 'is-at-least()' needs it.
+function zrcautoload () {
+ emulate -L zsh
+ setopt extended_glob
+ local fdir ffile
+ local -i ffound
+
+ ffile=$1
+ (( ffound = 0 ))
+ for fdir in ${fpath} ; do
+ [[ -e ${fdir}/${ffile} ]] && (( ffound = 1 ))
+ done
+
+ (( ffound == 0 )) && return 1
+ if [[ $ZSH_VERSION == 3.1.<6-> || $ZSH_VERSION == <4->* ]] ; then
+ autoload -U ${ffile} || return 1
+ else
+ autoload ${ffile} || return 1
+ fi
+ return 0
+}
+
+# The following is the ‘add-zsh-hook’ function from zsh upstream. It is
+# included here to make the setup work with older versions of zsh (prior to
+# 4.3.7) in which this function had a bug that triggers annoying errors during
+# shell startup. This is exactly upstreams code from f0068edb4888a4d8fe94def,
+# with just a few adjustments in coding style to make the function look more
+# compact. This definition can be removed as soon as we raise the minimum
+# version requirement to 4.3.7 or newer.
+function add-zsh-hook () {
+ # Add to HOOK the given FUNCTION.
+ # HOOK is one of chpwd, precmd, preexec, periodic, zshaddhistory,
+ # zshexit, zsh_directory_name (the _functions subscript is not required).
+ #
+ # With -d, remove the function from the hook instead; delete the hook
+ # variable if it is empty.
+ #
+ # -D behaves like -d, but pattern characters are active in the function
+ # name, so any matching function will be deleted from the hook.
+ #
+ # Without -d, the FUNCTION is marked for autoload; -U is passed down to
+ # autoload if that is given, as are -z and -k. (This is harmless if the
+ # function is actually defined inline.)
+ emulate -L zsh
+ local -a hooktypes
+ hooktypes=(
+ chpwd precmd preexec periodic zshaddhistory zshexit
+ zsh_directory_name
+ )
+ local usage="Usage: $0 hook function\nValid hooks are:\n $hooktypes"
+ local opt
+ local -a autoopts
+ integer del list help
+ while getopts "dDhLUzk" opt; do
+ case $opt in
+ (d) del=1 ;;
+ (D) del=2 ;;
+ (h) help=1 ;;
+ (L) list=1 ;;
+ ([Uzk]) autoopts+=(-$opt) ;;
+ (*) return 1 ;;
+ esac
+ done
+ shift $(( OPTIND - 1 ))
+ if (( list )); then
+ typeset -mp "(${1:-${(@j:|:)hooktypes}})_functions"
+ return $?
+ elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 )); then
+ print -u$(( 2 - help )) $usage
+ return $(( 1 - help ))
+ fi
+ local hook="${1}_functions"
+ local fn="$2"
+ if (( del )); then
+ # delete, if hook is set
+ if (( ${(P)+hook} )); then
+ if (( del == 2 )); then
+ set -A $hook ${(P)hook:#${~fn}}
+ else
+ set -A $hook ${(P)hook:#$fn}
+ fi
+ # unset if no remaining entries --- this can give better
+ # performance in some cases
+ if (( ! ${(P)#hook} )); then
+ unset $hook
+ fi
+ fi
+ else
+ if (( ${(P)+hook} )); then
+ if (( ${${(P)hook}[(I)$fn]} == 0 )); then
+ set -A $hook ${(P)hook} $fn
+ fi
+ else
+ set -A $hook $fn
+ fi
+ autoload $autoopts -- $fn
+ fi
+}
+
+# Load is-at-least() for more precise version checks Note that this test will
+# *always* fail, if the is-at-least function could not be marked for
+# autoloading.
+zrcautoload is-at-least || function is-at-least () { return 1 }
+
+# set some important options (as early as possible)
+
+# append history list to the history file; this is the default but we make sure
+# because it's required for share_history.
+setopt append_history
+
+# import new commands from the history file also in other zsh-session
+is4 && setopt share_history
+
+# save each command's beginning timestamp and the duration to the history file
+setopt extended_history
+
+# remove command lines from the history list when the first character on the
+# line is a space
+setopt histignorespace
+
+# if a command is issued that can't be executed as a normal command, and the
+# command is the name of a directory, perform the cd command to that directory.
+setopt auto_cd
+
+# in order to use #, ~ and ^ for filename generation grep word
+# *~(*.gz|*.bz|*.bz2|*.zip|*.Z) -> searches for word not in compressed files
+# don't forget to quote '^', '~' and '#'!
+setopt extended_glob
+
+# display PID when suspending processes as well
+setopt longlistjobs
+
+# report the status of backgrounds jobs immediately
+setopt notify
+
+# whenever a command completion is attempted, make sure the entire command path
+# is hashed first.
+setopt hash_list_all
+
+# not just at the end
+setopt completeinword
+
+# Don't send SIGHUP to background processes when the shell exits.
+setopt nohup
+
+# make cd push the old directory onto the directory stack.
+setopt auto_pushd
+
+# avoid "beep"ing
+setopt nobeep
+
+# don't push the same dir twice.
+setopt pushd_ignore_dups
+
+# * shouldn't match dotfiles. ever.
+setopt noglobdots
+
+# use zsh style word splitting
+setopt noshwordsplit
+
+# don't error out when unset parameters are used
+setopt unset
+
+# setting some default values
+NOCOR=${NOCOR:-0}
+NOETCHOSTS=${NOETCHOSTS:-0}
+NOMENU=${NOMENU:-0}
+NOPRECMD=${NOPRECMD:-0}
+COMMAND_NOT_FOUND=${COMMAND_NOT_FOUND:-0}
+GRML_ZSH_CNF_HANDLER=${GRML_ZSH_CNF_HANDLER:-/usr/share/command-not-found/command-not-found}
+GRML_DISPLAY_BATTERY=${GRML_DISPLAY_BATTERY:-${BATTERY:-0}}
+GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
+ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0}
+
+typeset -ga ls_options
+typeset -ga grep_options
+
+# Colors on GNU ls(1)
+if ls --color=auto / >/dev/null 2>&1; then
+ ls_options+=( --color=auto )
+# Colors on FreeBSD and OSX ls(1)
+elif ls -G / >/dev/null 2>&1; then
+ ls_options+=( -G )
+fi
+
+# Natural sorting order on GNU ls(1)
+# OSX and IllumOS have a -v option that is not natural sorting
+if ls --version |& grep -q 'GNU' >/dev/null 2>&1 && ls -v / >/dev/null 2>&1; then
+ ls_options+=( -v )
+fi
+
+# Color on GNU and FreeBSD grep(1)
+if grep --color=auto -q "a" <<< "a" >/dev/null 2>&1; then
+ grep_options+=( --color=auto )
+fi
+
+# utility functions