+ 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
+}
+
+# a "print -l ${(u)foo}"-workaround for pre-4.2.0 shells
+# usage: uprint foo
+# Where foo is the *name* of the parameter you want printed.
+# Note that foo is no typo; $foo would be wrong here!
+if ! is42 ; then
+ uprint () {
+ local -a u
+ local w
+ local parameter=${1}
+
+ if [[ -z ${parameter} ]] ; then
+ printf 'usage: uprint <parameter>\n'
+ return 1
+ fi
+
+ for w in ${(P)parameter} ; do
+ [[ -z ${(M)u:#${w}} ]] && u=( ${u} ${w} )
+ done
+
+ builtin print -l ${u}
+ }
+fi
+
+# 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=(salias xcat xsource xunfunction zrcautoload)
+
+ for func in $funcs ; do
+ [[ -n ${functions[$func]} ]] \
+ && unfunction $func
+ done
+ return 0
+}
+
+# autoload wrapper - use this one instead of autoload directly
+function zrcautoload() {
+ setopt local_options extended_glob
+ local fdir ffile
+ local -i ffound
+
+ ffile=${1}
+ (( found = 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
+}
+
+#}}}
+
+# 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 || is-at-least() { return 1 }
+
+# }}}
+
+# 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
+# }}}
+
+# {{{ set some variables
+if check_com -c vim ; then
+#v#
+ export EDITOR=${EDITOR:-vim}
+else
+ export EDITOR=${EDITOR:-vi}
+fi
+
+#v#
+export PAGER=${PAGER:-less}
+
+#v#
+export MAIL=${MAIL:-/var/mail/$USER}
+
+# if we don't set $SHELL then aterm, rxvt,.. will use /bin/sh or /bin/bash :-/
+export SHELL='/bin/zsh'
+
+# color setup for ls:
+check_com -c dircolors && eval $(dircolors -b)
+
+# set width of man pages to 80 for more convenient reading
+# export MANWIDTH=${MANWIDTH:-80}
+
+# Search path for the cd command
+# cdpath=(.. ~)
+
+# completion functions go to /etc/zsh/completion.d
+# function files may be put into /etc/zsh/functions.d, from where they
+# will be automatically autoloaded.
+if [[ -n "$BROKEN_COMPLETION_DIR" ]] ; then
+ print 'Warning: not setting completion directories because broken files have been found.' >&2
+else
+ [[ -d /etc/zsh/completion.d ]] && fpath=( $fpath /etc/zsh/completion.d )
+ if [[ -d /etc/zsh/functions.d ]] ; then
+ fpath+=( /etc/zsh/functions.d )
+ for func in /etc/zsh/functions.d/[^_]*[^~](N.) ; do
+ zrcautoload -U ${func:t}
+ done
+ fi
+fi
+
+# automatically remove duplicates from these arrays
+typeset -U path cdpath fpath manpath
+# }}}
+
+# {{{ keybindings
+if [[ "$TERM" != emacs ]] ; then
+ [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
+ [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
+ [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
+ [[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
+ [[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
+ [[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
+ [[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
+ [[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
+ [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
+ [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
+ [[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
+ [[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
+ # ncurses stuff:
+ [[ "$terminfo[kcuu1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
+ [[ "$terminfo[kcud1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
+ [[ "$terminfo[kcuf1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
+ [[ "$terminfo[kcub1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
+ [[ "$terminfo[khome]" == $'\eO'* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
+ [[ "$terminfo[kend]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
+ [[ "$terminfo[khome]" == $'\eO'* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
+ [[ "$terminfo[kend]" == $'\eO'* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
+fi
+
+## keybindings (run 'bindkeys' for details, more details via man zshzle)
+# use emacs style per default:
+bindkey -e
+# use vi style:
+# bindkey -v
+
+#if [[ "$TERM" == screen ]] ; then
+bindkey '\e[1~' beginning-of-line # home
+bindkey '\e[4~' end-of-line # end
+bindkey '\e[A' up-line-or-search # cursor up
+bindkey '\e[B' down-line-or-search # <ESC>-
+
+bindkey '^xp' history-beginning-search-backward
+bindkey '^xP' history-beginning-search-forward
+# bindkey -s '^L' "|less\n" # ctrl-L pipes to less
+# bindkey -s '^B' " &\n" # ctrl-B runs it in the background
+# if terminal type is set to 'rxvt':
+bindkey '\e[7~' beginning-of-line # home
+bindkey '\e[8~' end-of-line # end
+#fi
+
+# insert unicode character
+# usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an ยง
+# See for example http://unicode.org/charts/ for unicode characters code
+zrcautoload insert-unicode-char
+zle -N insert-unicode-char
+#k# Insert Unicode character
+bindkey '^Xi' insert-unicode-char
+
+# just type 'cd ...' to get 'cd ../..'
+# rationalise-dot() {
+# if [[ $LBUFFER == *.. ]] ; then
+# LBUFFER+=/..
+# else
+# LBUFFER+=.
+# fi
+# }
+# zle -N rationalise-dot
+# bindkey . rationalise-dot
+
+# bindkey '\eq' push-line-or-edit
+
+## toggle the ,. abbreviation feature on/off
+# NOABBREVIATION: default abbreviation-state
+# 0 - enabled (default)
+# 1 - disabled
+NOABBREVIATION=${NOABBREVIATION:-0}
+
+grml_toggle_abbrev() {
+ if (( ${NOABBREVIATION} > 0 )) ; then
+ NOABBREVIATION=0
+ else
+ NOABBREVIATION=1
+ fi
+}
+
+zle -N grml_toggle_abbrev
+bindkey '^xA' grml_toggle_abbrev
+
+# }}}
+
+# a generic accept-line wrapper {{{
+
+# This widget can prevent unwanted autocorrections from command-name
+# to _command-name, rehash automatically on enter and call any number
+# of builtin and user-defined widgets in different contexts.
+#
+# For a broader description, see:
+# <http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html>
+#
+# The code is imported from the file 'zsh/functions/accept-line' from
+# <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>, which
+# distributed under the same terms as zsh itself.
+
+# A newly added command will may not be found or will cause false
+# correction attempts, if you got auto-correction set. By setting the
+# following style, we force accept-line() to rehash, if it cannot
+# find the first word on the command line in the $command[] hash.
+zstyle ':acceptline:*' rehash true
+
+function Accept-Line() {
+ setopt localoptions noksharrays
+ local -a subs
+ local -xi aldone
+ local sub
+
+ zstyle -a ":acceptline:${alcontext}" actions subs
+
+ (( ${#subs} < 1 )) && return 0
+
+ (( aldone = 0 ))
+ for sub in ${subs} ; do
+ [[ ${sub} == 'accept-line' ]] && sub='.accept-line'
+ zle ${sub}
+
+ (( aldone > 0 )) && break
+ done
+}
+
+function Accept-Line-getdefault() {
+ local default_action
+
+ zstyle -s ":acceptline:${alcontext}" default_action default_action
+ case ${default_action} in
+ ((accept-line|))
+ printf ".accept-line"
+ ;;
+ (*)
+ printf ${default_action}
+ ;;
+ esac
+}
+
+function accept-line() {
+ setopt localoptions noksharrays
+ local -a cmdline
+ local -x alcontext
+ local buf com fname format msg default_action
+
+ alcontext='default'
+ buf="${BUFFER}"
+ cmdline=(${(z)BUFFER})
+ com="${cmdline[1]}"
+ fname="_${com}"
+
+ zstyle -t ":acceptline:${alcontext}" rehash \
+ && [[ -z ${commands[$com]} ]] \
+ && rehash
+
+ if [[ -n ${reswords[(r)$com]} ]] \
+ || [[ -n ${aliases[$com]} ]] \
+ || [[ -n ${functions[$com]} ]] \
+ || [[ -n ${builtins[$com]} ]] \
+ || [[ -n ${commands[$com]} ]] ; then
+
+ # there is something sensible to execute, just do it.
+ alcontext='normal'
+ zle Accept-Line
+
+ default_action=$(Accept-Line-getdefault)
+ zstyle -T ":acceptline:${alcontext}" call_default \
+ && zle ${default_action}
+ return
+ fi
+
+ if [[ -o correct ]] \
+ || [[ -o correctall ]] \
+ && [[ -n ${functions[$fname]} ]] ; then
+
+ # nothing there to execute but there is a function called
+ # _command_name; a completion widget. Makes no sense to
+ # call it on the commandline, but the correct{,all} options
+ # will ask for it nevertheless, so warn the user.
+ if [[ ${LASTWIDGET} == 'accept-line' ]] ; then
+ # Okay, we warned the user before, he called us again,
+ # so have it his way.
+ alcontext='force'
+ zle Accept-Line
+
+ default_action=$(Accept-Line-getdefault)
+ zstyle -T ":acceptline:${alcontext}" call_default \
+ && zle ${default_action}
+ return
+ fi
+
+ # prepare warning message for the user, configurable via zstyle.
+ zstyle -s ":acceptline:${alcontext}" compwarnfmt msg
+
+ if [[ -z ${msg} ]] ; then
+ msg="%c will not execute and completion %f exists."
+ fi
+
+ zformat -f msg "${msg}" "c:${com}" "f:${fname}"
+
+ zle -M -- "${msg}"
+ return
+ elif [[ -n ${buf//[$' \t\n']##/} ]] ; then
+ # If we are here, the commandline contains something that is not
+ # executable, which is neither subject to _command_name correction
+ # and is not empty. might be a variable assignment
+ alcontext='misc'
+ zle Accept-Line
+
+ default_action=$(Accept-Line-getdefault)
+ zstyle -T ":acceptline:${alcontext}" call_default \
+ && zle ${default_action}
+ return
+ fi
+
+ # If we got this far, the commandline only contains whitespace, or is empty.
+ alcontext='empty'
+ zle Accept-Line
+
+ default_action=$(Accept-Line-getdefault)
+ zstyle -T ":acceptline:${alcontext}" call_default \
+ && zle ${default_action}
+}
+
+zle -N accept-line
+zle -N Accept-Line
+
+# }}}
+
+# power completion - abbreviation expansion {{{
+# power completion / abbreviation expansion / buffer expansion
+# see http://zshwiki.org/home/examples/zleiab for details
+# less risky than the global aliases but powerful as well
+# just type the abbreviation key and afterwards ',.' to expand it
+declare -A abk
+setopt extendedglob
+setopt interactivecomments
+abk=(
+# key # value (#d additional doc string)
+#A# start
+ '...' '../..'
+ '....' '../../..'
+ 'BG' '& exit'
+ 'C' '| wc -l'
+ 'G' '|& grep --color=auto'
+ 'H' '| head'
+ 'Hl' ' --help |& less -r' #d (Display help in pager)
+ 'L' '| less'
+ 'LL' '|& less -r'
+ 'M' '| most'
+ 'N' '&>/dev/null' #d (No Output)
+ 'R' '| tr A-z N-za-m' #d (ROT13)
+ 'SL' '| sort | less'
+ 'S' '| sort -u'
+ 'T' '| tail'
+ 'V' '|& vim -'
+#A# end
+ 'hide' "echo -en '\033]50;nil2\007'"
+ 'tiny' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"'
+ 'small' 'echo -en "\033]50;6x10\007"'
+ 'medium' 'echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"'
+ 'default' 'echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"'
+ 'large' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"'
+ 'huge' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"'
+ 'smartfont' 'echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"'
+ 'semifont' 'echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"'
+ 'da' 'du -sch'
+ 'j' 'jobs -l'
+ 'u' 'translate -i'
+ 'co' "./configure && make && sudo make install"
+ 'CH' "./configure --help"
+ 'conkeror' 'firefox -chrome chrome://conkeror/content'
+ 'dir' 'ls -lSrah'
+ 'lad' $'ls -d .*(/)\n# only show dot-directories'
+ 'lsa' $'ls -a .*(.)\n# only show dot-files'
+ 'lss' $'ls -l *(s,S,t)\n# only files with setgid/setuid/sticky flag'
+ 'lsl' $'ls -l *(@[1,10])\n# only symlinks'
+ 'lsx' $'ls -l *(*[1,10])\n# only executables'
+ 'lsw' $'ls -ld *(R,W,X.^ND/)\n# world-{readable,writable,executable} files'
+ 'lsbig' $'ls -flh *(.OL[1,10])\n# display the biggest files'
+ 'lsd' $'ls -d *(/)\n# only show directories'
+ 'lse' $'ls -d *(/^F)\n# only show empty directories'
+ 'lsnew' $'ls -rl *(D.om[1,10])\n# display the newest files'
+ 'lsold' $'ls -rtlh *(D.om[-11,-1])\n # display the oldest files'
+ 'lssmall' $'ls -Srl *(.oL[1,10])\n# display the smallest files'
+ 'rw-' 'chmod 600'
+ '600' 'chmod u+rw-x,g-rwx,o-rwx'
+ 'rwx' 'chmod u+rwx'
+ '700' 'chmod u+rwx,g-rwx,o-rwx'
+ 'r--' 'chmod u+r-wx,g-rwx,o-rwx'
+ '644' $'chmod u+rw-x,g+r-wx,o+r-wx\n # 4=r,2=w,1=x'
+ '755' 'chmod u+rwx,g+r-w+x,o+r-w+x'
+ 'md' 'mkdir -p '
+ 'cmplayer' 'mplayer -vo -fs -zoom fbdev'
+ 'fbmplayer' 'mplayer -vo -fs -zoom fbdev'
+ 'fblinks' 'links2 -driver fb'
+ 'insecssh' 'ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
+ 'insecscp' 'scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
+ 'fori' 'for i ({..}) { }'
+ 'cx' 'chmod +x'
+ 'e' 'print -l'
+ 'se' 'setopt interactivecomments'
+ 'va' 'valac --vapidir=../vapi/ --pkg=gtk+-2.0 gtktest.vala'
+ 'fb2' '=mplayer -vo fbdev -fs -zoom 1>/dev/null -xy 2'
+ 'fb3' '=mplayer -vo fbdev -fs -zoom 1>/dev/null -xy 3'
+ 'ci' 'centericq'
+ 'D' 'export DISPLAY=:0.0'
+ 'mp' 'mplayer -vo xv -fs -zoom'
+)
+
+globalias() {
+ local MATCH
+
+ if (( NOABBREVIATION > 0 )) ; then
+ LBUFFER="${LBUFFER},."