+ # match uppercase from lowercase
+ zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
+
+ # separate matches into groups
+ zstyle ':completion:*:matches' group 'yes'
+ zstyle ':completion:*' group-name ''
+
+ if [[ "$NOMENU" -eq 0 ]] ; then
+ # if there are more than 5 options allow selecting from a menu
+ zstyle ':completion:*' menu select=5
+ else
+ # don't use any menus at all
+ setopt no_auto_menu
+ fi
+
+ zstyle ':completion:*:messages' format '%d'
+ zstyle ':completion:*:options' auto-description '%d'
+
+ # describe options in full
+ zstyle ':completion:*:options' description 'yes'
+
+ # on processes completion complete all user processes
+ zstyle ':completion:*:processes' command 'ps -au$USER'
+
+ # offer indexes before parameters in subscripts
+ zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
+
+ # provide verbose completion information
+ zstyle ':completion:*' verbose true
+
+ # recent (as of Dec 2007) zsh versions are able to provide descriptions
+ # for commands (read: 1st word in the line) that it will list for the user
+ # to choose from. The following disables that, because it's not exactly fast.
+ zstyle ':completion:*:-command-:*:' verbose false
+
+ # set format for warnings
+ zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
+
+ # define files to ignore for zcompile
+ zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
+ zstyle ':completion:correct:' prompt 'correct to: %e'
+
+ # Ignore completion functions for commands you don't have:
+ zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
+
+ # Provide more processes in completion of programs like killall:
+ zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
+
+ # complete manual by their section
+ zstyle ':completion:*:manuals' separate-sections true
+ zstyle ':completion:*:manuals.*' insert-sections true
+ zstyle ':completion:*:man:*' menu yes select
+
+ # Search path for sudo completion
+ zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
+ /usr/local/bin \
+ /usr/sbin \
+ /usr/bin \
+ /sbin \
+ /bin \
+ /usr/X11R6/bin
+
+ # provide .. as a completion
+ zstyle ':completion:*' special-dirs ..
+
+ # run rehash on completion so new installed program are found automatically:
+ _force_rehash() {
+ (( CURRENT == 1 )) && rehash
+ return 1
+ }
+
+ ## correction
+ # some people don't like the automatic correction - so run 'NOCOR=1 zsh' to deactivate it
+ if [[ "$NOCOR" -gt 0 ]] ; then
+ zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _files _ignored
+ setopt nocorrect
+ else
+ # try to be smart about when to use what completer...
+ setopt correct
+ zstyle -e ':completion:*' completer '
+ if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]] ; then
+ _last_try="$HISTNO$BUFFER$CURSOR"
+ reply=(_complete _match _ignored _prefix _files)
+ else
+ if [[ $words[1] == (rm|mv) ]] ; then
+ reply=(_complete _files)
+ else
+ reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
+ fi
+ fi'
+ fi
+
+ # command for process lists, the local web server details and host completion
+ zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
+
+ # caching
+ [[ -d $ZSHDIR/cache ]] && zstyle ':completion:*' use-cache yes && \
+ zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
+
+ # host completion
+ if is42 ; then
+ [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
+ [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
+ else
+ _ssh_hosts=()
+ _etc_hosts=()
+ fi
+ hosts=(
+ $(hostname)
+ "$_ssh_hosts[@]"
+ "$_etc_hosts[@]"
+ localhost
+ )
+ zstyle ':completion:*:hosts' hosts $hosts
+ # TODO: so, why is this here?
+ # zstyle '*' hosts $hosts
+
+ # use generic completion system for programs not yet defined; (_gnu_generic works
+ # with commands that provide a --help option with "standard" gnu-like output.)
+ for compcom in cp deborphan df feh fetchipac head hnb ipacsum mv \
+ pal stow tail uname ; do
+ [[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
+ done; unset compcom
+
+ # see upgrade function in this file
+ compdef _hosts upgrade
+}
+
+# Keyboard setup: The following is based on the same code, we wrote for
+# debian's setup. It ensures the terminal is in the right mode, when zle is
+# active, so the values from $terminfo are valid. Therefore, this setup should
+# work on all systems, that have support for `terminfo'. It also requires the
+# zsh in use to have the `zsh/terminfo' module built.
+#
+# If you are customising your `zle-line-init()' or `zle-line-finish()'
+# functions, make sure you call the following utility functions in there:
+#
+# - zle-line-init(): zle-smkx
+# - zle-line-finish(): zle-rmkx
+
+# Use emacs-like key bindings by default:
+bindkey -e
+
+# Custom widgets:
+
+## beginning-of-line OR beginning-of-buffer OR beginning of history
+## by: Bart Schaefer <schaefer@brasslantern.com>, Bernhard Tittelbach
+beginning-or-end-of-somewhere() {
+ local hno=$HISTNO
+ if [[ ( "${LBUFFER[-1]}" == $'\n' && "${WIDGET}" == beginning-of* ) || \
+ ( "${RBUFFER[1]}" == $'\n' && "${WIDGET}" == end-of* ) ]]; then
+ zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
+ else
+ zle .${WIDGET:s/somewhere/line-hist/} "$@"
+ if (( HISTNO != hno )); then
+ zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
+ fi
+ fi
+}
+zle -N beginning-of-somewhere beginning-or-end-of-somewhere
+zle -N end-of-somewhere beginning-or-end-of-somewhere
+
+## 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
+
+# add a command line to the shells history without executing it
+commit-to-history() {
+ print -s ${(z)BUFFER}
+ zle send-break
+}
+zle -N commit-to-history
+
+# only slash should be considered as a word separator:
+slash-backward-kill-word() {
+ local WORDCHARS="${WORDCHARS:s@/@}"
+ # zle backward-word
+ zle backward-kill-word
+}
+zle -N slash-backward-kill-word
+
+# 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
+ local alcontext=${1:-$alcontext}
+
+ 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() {
+ emulate -L zsh
+ 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-HandleContext() {
+ zle Accept-Line
+
+ default_action=$(Accept-Line-getdefault)
+ zstyle -T ":acceptline:${alcontext}" call_default \
+ && zle ${default_action}
+}
+
+function accept-line() {
+ setopt localoptions noksharrays
+ local -ax cmdline
+ local -x alcontext
+ local buf com fname format msg default_action
+
+ alcontext='default'
+ buf="${BUFFER}"
+ cmdline=(${(z)BUFFER})
+ com="${cmdline[1]}"
+ fname="_${com}"
+
+ Accept-Line 'preprocess'
+
+ zstyle -t ":acceptline:${alcontext}" rehash \
+ && [[ -z ${commands[$com]} ]] \
+ && rehash
+
+ if [[ -n ${com} ]] \
+ && [[ -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'
+ Accept-Line-HandleContext
+
+ 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'
+ Accept-Line-HandleContext
+
+ return
+ fi
+
+ if zstyle -t ":acceptline:${alcontext}" nocompwarn ; then
+ alcontext='normal'
+ Accept-Line-HandleContext
+ else
+ # 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}"
+ fi
+ 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'
+ Accept-Line-HandleContext
+
+ return
+ fi
+
+ # If we got this far, the commandline only contains whitespace, or is empty.
+ alcontext='empty'
+ Accept-Line-HandleContext
+}
+
+zle -N accept-line
+zle -N Accept-Line
+zle -N Accept-Line-HandleContext
+
+# 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 '${grep_options:+"${grep_options[*]}"}
+ '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
+ 'co' './configure && make && sudo make install'
+)
+
+zleiab() {
+ emulate -L zsh
+ setopt extendedglob
+ local MATCH
+
+ if (( NOABBREVIATION > 0 )) ; then
+ LBUFFER="${LBUFFER},."
+ return 0
+ fi
+
+ LBUFFER=${LBUFFER%%(#m)[.\-+:|_a-zA-Z0-9]#}
+ LBUFFER+=${abk[$MATCH]:-$MATCH}
+}
+
+zle -N zleiab
+
+help-show-abk()
+{
+ zle -M "$(print "Type ,. after these abbreviations to expand them:"; print -a -C 2 ${(kv)abk})"
+}
+
+zle -N help-show-abk
+
+# press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
+insert-datestamp() { LBUFFER+=${(%):-'%D{%Y-%m-%d}'}; }
+zle -N insert-datestamp
+
+# press esc-m for inserting last typed word again (thanks to caphuso!)
+insert-last-typed-word() { zle insert-last-word -- 0 -1 };
+zle -N insert-last-typed-word;
+
+function grml-zsh-fg() {
+ if (( ${#jobstates} )); then
+ zle .push-input
+ [[ -o hist_ignore_space ]] && BUFFER=' ' || BUFFER=''
+ BUFFER="${BUFFER}fg"
+ zle .accept-line
+ else
+ zle -M 'No background jobs. Doing nothing.'
+ fi
+}
+zle -N grml-zsh-fg
+
+# run command line as user root via sudo: