+# 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
+
+#k# Kill left-side word or everything up to next slash
+bindkey '\ev' slash-backward-kill-word
+#k# Kill left-side word or everything up to next slash
+bindkey '\e^h' slash-backward-kill-word
+#k# Kill left-side word or everything up to next slash
+bindkey '\e^?' slash-backward-kill-word
+
+# use the new *-pattern-* widgets for incremental history search
+if is439 ; then
+ bindkey '^r' history-incremental-pattern-search-backward
+ bindkey '^s' history-incremental-pattern-search-forward
+fi
+
+# 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
+
+ matched_chars='[.-|_a-zA-Z0-9]#'
+ LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#}
+ LBUFFER+=${abk[$MATCH]:-$MATCH}
+}
+
+zle -N zleiab && bindkey ",." zleiab
+
+#f# display contents of assoc array $abk
+help-show-abk()
+{
+ zle -M "$(print "Type ,. after these abbreviations to expand them:"; print -a -C 2 ${(kv)abk})"
+}
+#k# Display list of abbreviations that expand when followed by ,.
+zle -N help-show-abk && bindkey '^xb' help-show-abk
+
+# autoloading
+zrcautoload zmv # who needs mmv or rename?
+zrcautoload history-search-end
+
+# we don't want to quote/espace URLs on our own...
+# if autoload -U url-quote-magic ; then
+# zle -N self-insert url-quote-magic
+# zstyle ':url-quote-magic:*' url-metas '*?[]^()~#{}='
+# else
+# print 'Notice: no url-quote-magic available :('
+# fi
+alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic'
+
+#m# k ESC-h Call \kbd{run-help} for the 1st word on the command line
+alias run-help >&/dev/null && unalias run-help
+for rh in run-help{,-git,-svk,-svn}; do
+ zrcautoload $rh
+done; unset rh
+
+# completion system
+if zrcautoload compinit ; then
+ compinit || print 'Notice: no compinit available :('
+else
+ print 'Notice: no compinit available :('
+ function compdef { }
+fi
+
+is4 && zrcautoload zed # use ZLE editor to edit a file or function
+
+is4 && \
+for mod in complist deltochar mathfunc ; do
+ zmodload -i zsh/${mod} 2>/dev/null || print "Notice: no ${mod} available :("
+done
+
+# autoload zsh modules when they are referenced
+if is4 ; then
+ zmodload -a zsh/stat zstat
+ zmodload -a zsh/zpty zpty
+ zmodload -ap zsh/mapfile mapfile
+fi
+
+if is4 && zrcautoload insert-files && zle -N insert-files ; then
+ #k# Insert files and test globbing
+ bindkey "^xf" insert-files # C-x-f
+fi
+
+bindkey ' ' magic-space # also do history expansion on space
+#k# Trigger menu-complete
+bindkey '\ei' menu-complete # menu completion via esc-i
+
+# press esc-e for editing command line in $EDITOR or $VISUAL
+if is4 && zrcautoload edit-command-line && zle -N edit-command-line ; then
+ #k# Edit the current line in \kbd{\$EDITOR}
+ bindkey '\ee' edit-command-line
+fi
+
+if is4 && [[ -n ${(k)modules[zsh/complist]} ]] ; then
+ #k# menu selection: pick item but stay in the menu
+ bindkey -M menuselect '\e^M' accept-and-menu-complete
+ # also use + and INSERT since it's easier to press repeatedly
+ bindkey -M menuselect "+" accept-and-menu-complete
+ bindkey -M menuselect "^[[2~" accept-and-menu-complete
+
+ # accept a completion and try to complete again by using menu
+ # completion; very useful with completing directories
+ # by using 'undo' one's got a simple file browser
+ bindkey -M menuselect '^o' accept-and-infer-next-history
+fi
+
+# 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
+
+#k# Insert a timestamp on the command line (yyyy-mm-dd)
+bindkey '^ed' 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;
+
+#k# Insert last typed word
+bindkey "\em" 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
+#k# A smart shortcut for \kbd{fg<enter>}
+bindkey '^z' grml-zsh-fg
+
+# run command line as user root via sudo:
+sudo-command-line() {
+ [[ -z $BUFFER ]] && zle up-history
+ if [[ $BUFFER != sudo\ * ]]; then
+ BUFFER="sudo $BUFFER"
+ CURSOR=$(( CURSOR+5 ))
+ fi
+}
+zle -N sudo-command-line
+
+#k# prepend the current command with "sudo"
+bindkey "^os" sudo-command-line
+
+### jump behind the first word on the cmdline.
+### useful to add options.
+function jump_after_first_word() {
+ local words
+ words=(${(z)BUFFER})
+
+ if (( ${#words} <= 1 )) ; then
+ CURSOR=${#BUFFER}
+ else
+ CURSOR=${#${words[1]}}
+ fi
+}
+zle -N jump_after_first_word
+#k# jump to after first word (for adding options)
+bindkey '^x1' jump_after_first_word
+
+# complete word from history with menu (from Book: ZSH, OpenSource-Press)
+zle -C hist-complete complete-word _generic
+zstyle ':completion:hist-complete:*' completer _history
+#k# complete word from history with menu
+bindkey "^x^x" hist-complete
+
+## complete word from currently visible Screen or Tmux buffer.
+if check_com -c screen || check_com -c tmux; then
+ _complete_screen_display() {
+ [[ "$TERM" != "screen" ]] && return 1
+
+ local TMPFILE=$(mktemp)
+ local -U -a _screen_display_wordlist
+ trap "rm -f $TMPFILE" EXIT
+
+ # fill array with contents from screen hardcopy
+ if ((${+TMUX})); then
+ #works, but crashes tmux below version 1.4
+ #luckily tmux -V option to ask for version, was also added in 1.4
+ tmux -V &>/dev/null || return
+ tmux -q capture-pane \; save-buffer -b 0 $TMPFILE \; delete-buffer -b 0
+ else
+ screen -X hardcopy $TMPFILE
+ # screen sucks, it dumps in latin1, apparently always. so recode it
+ # to system charset
+ check_com recode && recode latin1 $TMPFILE
+ fi
+ _screen_display_wordlist=( ${(QQ)$(<$TMPFILE)} )
+ # remove PREFIX to be completed from that array
+ _screen_display_wordlist[${_screen_display_wordlist[(i)$PREFIX]}]=""
+ compadd -a _screen_display_wordlist
+ }
+ #k# complete word from currently visible GNU screen buffer
+ bindkey -r "^xS"
+ compdef -k _complete_screen_display complete-word '^xS'
+fi
+
+# history
+
+ZSHDIR=$HOME/.zsh
+
+#v#
+HISTFILE=$HOME/.zsh_history
+isgrmlcd && HISTSIZE=500 || HISTSIZE=5000
+isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history
+
+# dirstack handling
+
+DIRSTACKSIZE=${DIRSTACKSIZE:-20}
+DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs}
+
+if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
+ dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
+ # "cd -" won't work after login by just setting $OLDPWD, so
+ [[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
+fi
+
+chpwd() {
+ local -ax my_stack
+ my_stack=( ${PWD} ${dirstack} )
+ if is42 ; then
+ builtin print -l ${(u)my_stack} >! ${DIRSTACKFILE}
+ else
+ uprint my_stack >! ${DIRSTACKFILE}
+ fi
+}
+
+# directory based profiles
+
+if is433 ; then
+
+# chpwd_profiles(): Directory Profiles, Quickstart:
+#
+# In .zshrc.local:
+#
+# zstyle ':chpwd:profiles:/usr/src/grml(|/|/*)' profile grml
+# zstyle ':chpwd:profiles:/usr/src/debian(|/|/*)' profile debian
+# chpwd_profiles
+#
+# For details see the `grmlzshrc.5' manual page.
+function chpwd_profiles() {
+ local profile context
+ local -i reexecute
+
+ context=":chpwd:profiles:$PWD"
+ zstyle -s "$context" profile profile || profile='default'
+ zstyle -T "$context" re-execute && reexecute=1 || reexecute=0
+
+ if (( ${+parameters[CHPWD_PROFILE]} == 0 )); then
+ typeset -g CHPWD_PROFILE
+ local CHPWD_PROFILES_INIT=1
+ (( ${+functions[chpwd_profiles_init]} )) && chpwd_profiles_init
+ elif [[ $profile != $CHPWD_PROFILE ]]; then
+ (( ${+functions[chpwd_leave_profile_$CHPWD_PROFILE]} )) \
+ && chpwd_leave_profile_${CHPWD_PROFILE}
+ fi
+ if (( reexecute )) || [[ $profile != $CHPWD_PROFILE ]]; then
+ (( ${+functions[chpwd_profile_$profile]} )) && chpwd_profile_${profile}
+ fi
+
+ CHPWD_PROFILE="${profile}"
+ return 0
+}
+
+chpwd_functions=( ${chpwd_functions} chpwd_profiles )
+
+fi # is433
+
+# display battery status on right side of prompt via running 'BATTERY=1 zsh'
+if [[ $BATTERY -gt 0 ]] ; then
+ if ! check_com -c acpi ; then
+ BATTERY=0
+ fi
+fi
+
+battery() {
+if [[ $BATTERY -gt 0 ]] ; then
+ PERCENT="${${"$(acpi 2>/dev/null)"}/(#b)[[:space:]]#Battery <->: [^0-9]##, (<->)%*/${match[1]}}"
+ if [[ -z "$PERCENT" ]] ; then
+ PERCENT='acpi not present'
+ else
+ if [[ "$PERCENT" -lt 20 ]] ; then
+ PERCENT="warning: ${PERCENT}%%"
+ else
+ PERCENT="${PERCENT}%%"
+ fi
+ fi
+fi
+}
+# set colors for use in prompts
+if zrcautoload colors && colors 2>/dev/null ; then
+ BLUE="%{${fg[blue]}%}"
+ RED="%{${fg_bold[red]}%}"
+ GREEN="%{${fg[green]}%}"
+ CYAN="%{${fg[cyan]}%}"
+ MAGENTA="%{${fg[magenta]}%}"
+ YELLOW="%{${fg[yellow]}%}"
+ WHITE="%{${fg[white]}%}"
+ NO_COLOUR="%{${reset_color}%}"
+else
+ BLUE=$'%{\e[1;34m%}'
+ RED=$'%{\e[1;31m%}'
+ GREEN=$'%{\e[1;32m%}'
+ CYAN=$'%{\e[1;36m%}'
+ WHITE=$'%{\e[1;37m%}'
+ MAGENTA=$'%{\e[1;35m%}'
+ YELLOW=$'%{\e[1;33m%}'
+ NO_COLOUR=$'%{\e[0m%}'
+fi
+
+# gather version control information for inclusion in a prompt
+
+if zrcautoload vcs_info; then
+ # `vcs_info' in zsh versions 4.3.10 and below have a broken `_realpath'
+ # function, which can cause a lot of trouble with our directory-based
+ # profiles. So:
+ if [[ ${ZSH_VERSION} == 4.3.<-10> ]] ; then
+ function VCS_INFO_realpath () {
+ setopt localoptions NO_shwordsplit chaselinks
+ ( builtin cd -q $1 2> /dev/null && pwd; )
+ }
+ fi
+
+ zstyle ':vcs_info:*' max-exports 2
+
+ if [[ -o restricted ]]; then
+ zstyle ':vcs_info:*' enable NONE
+ fi
+fi
+
+# Change vcs_info formats for the grml prompt. The 2nd format sets up
+# $vcs_info_msg_1_ to contain "zsh: repo-name" used to set our screen title.
+# TODO: The included vcs_info() version still uses $VCS_INFO_message_N_.
+# That needs to be the use of $VCS_INFO_message_N_ needs to be changed
+# to $vcs_info_msg_N_ as soon as we use the included version.
+if [[ "$TERM" == dumb ]] ; then
+ zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] " "zsh: %r"
+ zstyle ':vcs_info:*' formats "(%s%)-[%b] " "zsh: %r"
+else
+ # these are the same, just with a lot of colours:
+ zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOUR} " \
+ "zsh: %r"
+ zstyle ':vcs_info:*' formats "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOUR}%} " \
+ "zsh: %r"
+ zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YELLOW}%r"
+fi
+
+# command not found handling
+
+(( ${COMMAND_NOT_FOUND} == 1 )) &&
+function command_not_found_handler() {
+ emulate -L zsh
+ if [[ -x ${GRML_ZSH_CNF_HANDLER} ]] ; then
+ ${GRML_ZSH_CNF_HANDLER} $1
+ fi
+ return 1
+}
+
+# set prompt
+if zrcautoload promptinit && promptinit 2>/dev/null ; then
+ promptinit # people should be able to use their favourite prompt
+else
+ print 'Notice: no promptinit available :('
+fi
+
+setopt prompt_subst
+
+# make sure to use right prompt only when not running a command
+is41 && setopt transient_rprompt
+
+
+function ESC_print () {
+ info_print $'\ek' $'\e\\' "$@"
+}
+function set_title () {
+ info_print $'\e]0;' $'\a' "$@"
+}
+
+function info_print () {
+ local esc_begin esc_end
+ esc_begin="$1"
+ esc_end="$2"
+ shift 2
+ printf '%s' ${esc_begin}
+ printf '%s' "$*"
+ printf '%s' "${esc_end}"
+}
+
+# TODO: revise all these NO* variables and especially their documentation
+# in zsh-help() below.
+is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
+ [[ $NOPRECMD -gt 0 ]] && return 0
+ # update VCS information
+ (( ${+functions[vcs_info]} )) && vcs_info
+
+ if [[ $TERM == screen* ]] ; then
+ if [[ -n ${vcs_info_msg_1_} ]] ; then
+ ESC_print ${vcs_info_msg_1_}
+ else
+ ESC_print "zsh"
+ fi
+ fi
+ # just use DONTSETRPROMPT=1 to be able to overwrite RPROMPT
+ if [[ ${DONTSETRPROMPT:-} -eq 0 ]] ; then
+ if [[ $BATTERY -gt 0 ]] ; then
+ # update battery (dropped into $PERCENT) information
+ battery
+ RPROMPT="%(?..:() ${PERCENT}"
+ else
+ RPROMPT="%(?..:() "
+ fi
+ fi
+ # adjust title of xterm
+ # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
+ [[ ${NOTITLE:-} -gt 0 ]] && return 0
+ case $TERM in
+ (xterm*|rxvt*)
+ set_title ${(%):-"%n@%m: %~"}
+ ;;
+ esac
+}
+
+# preexec() => a function running before every command
+is4 && [[ $NOPRECMD -eq 0 ]] && \
+preexec () {
+ [[ $NOPRECMD -gt 0 ]] && return 0
+# set hostname if not running on host with name 'grml'
+ if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != $(hostname) ]] ; then
+ NAME="@$HOSTNAME"
+ fi
+# get the name of the program currently running and hostname of local machine
+# set screen window title if running in a screen
+ if [[ "$TERM" == screen* ]] ; then
+ # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} # don't use hostname
+ local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
+ ESC_print ${CMD}
+ fi
+# adjust title of xterm
+ [[ ${NOTITLE} -gt 0 ]] && return 0
+ case $TERM in
+ (xterm*|rxvt*)
+ set_title "${(%):-"%n@%m:"}" "$1"
+ ;;
+ esac
+}
+
+EXITCODE="%(?..%?%1v )"
+# secondary prompt, printed when the shell needs more information to complete a
+# command.
+PS2='\`%_> '
+# selection prompt used within a select loop.
+PS3='?# '
+# the execution trace prompt (setopt xtrace). default: '+%N:%i>'
+PS4='+%N:%i:%_> '
+
+# set variable debian_chroot if running in a chroot with /etc/debian_chroot
+if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
+ debian_chroot=$(cat /etc/debian_chroot)
+fi
+
+# don't use colors on dumb terminals (like emacs):
+if [[ "$TERM" == dumb ]] ; then
+ PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< "
+else
+ # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended
+ # prompt set variable identifying the chroot you work in (used in the
+ # prompt below)
+ if [[ $GRMLPROMPT -gt 0 ]] ; then
+ PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
+${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
+ else
+ # This assembles the primary prompt string
+ if (( EUID != 0 )); then
+ PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
+ else
+ PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
+ fi
+ fi
+fi
+
+PROMPT="${PROMPT}"'${vcs_info_msg_0_}'"%# "
+
+# if we are inside a grml-chroot set a specific prompt theme
+if [[ -n "$GRML_CHROOT" ]] ; then
+ PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "
+fi
+
+# 'hash' some often used directories
+#d# start
+hash -d deb=/var/cache/apt/archives
+hash -d doc=/usr/share/doc
+hash -d linux=/lib/modules/$(command uname -r)/build/
+hash -d log=/var/log
+hash -d slog=/var/log/syslog
+hash -d src=/usr/src
+hash -d templ=/usr/share/doc/grml-templates
+hash -d tt=/usr/share/doc/texttools-doc
+hash -d www=/var/www
+#d# end
+
+# some aliases
+if check_com -c screen ; then
+ if [[ $UID -eq 0 ]] ; then
+ if [[ -r /etc/grml/screenrc ]]; then
+ alias screen="${commands[screen]} -c /etc/grml/screenrc"
+ fi
+ elif [[ -r $HOME/.screenrc ]] ; then
+ alias screen="${commands[screen]} -c $HOME/.screenrc"
+ else
+ if [[ -r /etc/grml/screenrc_grml ]]; then
+ alias screen="${commands[screen]} -c /etc/grml/screenrc_grml"
+ else
+ if [[ -r /etc/grml/screenrc ]]; then
+ alias screen="${commands[screen]} -c /etc/grml/screenrc"
+ fi
+ fi
+ fi
+fi
+
+# do we have GNU ls with color-support?
+if [[ "$TERM" != dumb ]]; then
+ #a1# execute \kbd{@a@}:\quad ls with colors
+ alias ls='ls -b -CF '${ls_options:+"${ls_options[*]}"}
+ #a1# execute \kbd{@a@}:\quad list all files, with colors
+ alias la='ls -la '${ls_options:+"${ls_options[*]}"}
+ #a1# long colored list, without dotfiles (@a@)
+ alias ll='ls -l '${ls_options:+"${ls_options[*]}"}
+ #a1# long colored list, human readable sizes (@a@)
+ alias lh='ls -hAl '${ls_options:+"${ls_options[*]}"}
+ #a1# List files, append qualifier to filenames \\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...)
+ alias l='ls -lF '${ls_options:+"${ls_options[*]}"}
+else
+ alias ls='ls -b -CF'
+ alias la='ls -la'
+ alias ll='ls -l'
+ alias lh='ls -hAl'
+ alias l='ls -lF'
+fi
+
+alias mdstat='cat /proc/mdstat'
+alias ...='cd ../../'
+
+# generate alias named "$KERNELVERSION-reboot" so you can use boot with kexec:
+if [[ -x /sbin/kexec ]] && [[ -r /proc/cmdline ]] ; then
+ alias "$(uname -r)-reboot"="kexec -l --initrd=/boot/initrd.img-"$(uname -r)" --command-line=\"$(cat /proc/cmdline)\" /boot/vmlinuz-"$(uname -r)""
+fi
+
+# see http://www.cl.cam.ac.uk/~mgk25/unicode.html#term for details
+alias term2iso="echo 'Setting terminal to iso mode' ; print -n '\e%@'"
+alias term2utf="echo 'Setting terminal to utf-8 mode'; print -n '\e%G'"
+
+# make sure it is not assigned yet
+[[ -n ${aliases[utf2iso]} ]] && unalias utf2iso
+utf2iso() {
+ if isutfenv ; then
+ for ENV in $(env | command grep -i '.utf') ; do
+ eval export "$(echo $ENV | sed 's/UTF-8/iso885915/ ; s/utf8/iso885915/')"
+ done
+ fi
+}
+
+# make sure it is not assigned yet
+[[ -n ${aliases[iso2utf]} ]] && unalias iso2utf
+iso2utf() {
+ if ! isutfenv ; then
+ for ENV in $(env | command grep -i '\.iso') ; do
+ eval export "$(echo $ENV | sed 's/iso.*/UTF-8/ ; s/ISO.*/UTF-8/')"
+ done
+ fi
+}
+
+# especially for roadwarriors using GNU screen and ssh:
+if ! check_com asc &>/dev/null ; then
+ asc() { autossh -t "$@" 'screen -RdU' }
+ compdef asc=ssh
+fi
+
+#f1# Hints for the use of zsh on grml
+zsh-help() {
+ print "$bg[white]$fg[black]
+zsh-help - hints for use of zsh on grml
+=======================================$reset_color"
+
+ print '
+Main configuration of zsh happens in /etc/zsh/zshrc.
+That file is part of the package grml-etc-core, if you want to
+use them on a non-grml-system just get the tar.gz from
+http://deb.grml.org/ or (preferably) get it from the git repository:
+
+ http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc
+
+This version of grml'\''s zsh setup does not use skel/.zshrc anymore.
+The file is still there, but it is empty for backwards compatibility.
+
+For your own changes use these two files:
+ $HOME/.zshrc.pre
+ $HOME/.zshrc.local
+
+The former is sourced very early in our zshrc, the latter is sourced
+very lately.
+
+System wide configuration without touching configuration files of grml
+can take place in /etc/zsh/zshrc.local.
+
+For information regarding zsh start at http://grml.org/zsh/
+
+Take a look at grml'\''s zsh refcard:
+% xpdf =(zcat /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)
+
+Check out the main zsh refcard:
+% '$BROWSER' http://www.bash2zsh.com/zsh_refcard/refcard.pdf
+
+And of course visit the zsh-lovers:
+% man zsh-lovers
+
+You can adjust some options through environment variables when
+invoking zsh without having to edit configuration files.
+Basically meant for bash users who are not used to the power of
+the zsh yet. :)
+
+ "NOCOR=1 zsh" => deactivate automatic correction
+ "NOMENU=1 zsh" => do not use auto menu completion
+ (note: use ctrl-d for completion instead!)
+ "NOPRECMD=1 zsh" => disable the precmd + preexec commands (set GNU screen title)
+ "NOTITLE=1 zsh" => disable setting the title of xterms without disabling
+ preexec() and precmd() completely
+ "BATTERY=1 zsh" => activate battery status (via acpi) on right side of prompt
+ "COMMAND_NOT_FOUND=1 zsh"
+ => Enable a handler if an external command was not found
+ The command called in the handler can be altered by setting
+ the GRML_ZSH_CNF_HANDLER variable, the default is:
+ "/usr/share/command-not-found/command-not-found"
+
+A value greater than 0 is enables a feature; a value equal to zero
+disables it. If you like one or the other of these settings, you can
+add them to ~/.zshrc.pre to ensure they are set when sourcing grml'\''s
+zshrc.'
+
+ print "
+$bg[white]$fg[black]
+Please report wishes + bugs to the grml-team: http://grml.org/bugs/
+Enjoy your grml system with the zsh!$reset_color"
+}
+
+# debian stuff
+if [[ -r /etc/debian_version ]] ; then
+ #a3# Execute \kbd{apt-cache search}
+ alias acs='apt-cache search'
+ #a3# Execute \kbd{apt-cache show}
+ alias acsh='apt-cache show'
+ #a3# Execute \kbd{apt-cache policy}
+ alias acp='apt-cache policy'
+ #a3# Execute \kbd{apt-get dist-upgrade}
+ salias adg="apt-get dist-upgrade"
+ #a3# Execute \kbd{apt-get install}
+ salias agi="apt-get install"
+ #a3# Execute \kbd{aptitude install}
+ salias ati="aptitude install"
+ #a3# Execute \kbd{apt-get upgrade}
+ salias ag="apt-get upgrade"
+ #a3# Execute \kbd{apt-get update}
+ salias au="apt-get update"
+ #a3# Execute \kbd{aptitude update ; aptitude safe-upgrade}
+ salias -a up="aptitude update ; aptitude safe-upgrade"
+ #a3# Execute \kbd{dpkg-buildpackage}
+ alias dbp='dpkg-buildpackage'
+ #a3# Execute \kbd{grep-excuses}
+ alias ge='grep-excuses'
+
+ # get a root shell as normal user in live-cd mode:
+ if isgrmlcd && [[ $UID -ne 0 ]] ; then
+ alias su="sudo su"
+ fi
+
+ #a1# Take a look at the syslog: \kbd{\$PAGER /var/log/syslog}
+ salias llog="$PAGER /var/log/syslog" # take a look at the syslog
+ #a1# Take a look at the syslog: \kbd{tail -f /var/log/syslog}
+ salias tlog="tail -f /var/log/syslog" # follow the syslog
+fi
+
+# sort installed Debian-packages by size
+if check_com -c dpkg-query ; then
+ #a3# List installed Debian-packages sorted by size
+ alias debs-by-size="dpkg-query -Wf 'x \${Installed-Size} \${Package} \${Status}\n' | sed -ne '/^x /d' -e '/^x \(.*\) install ok installed$/s//\1/p' | sort -nr"
+fi
+
+# if cdrecord is a symlink (to wodim) or isn't present at all warn:
+if [[ -L /usr/bin/cdrecord ]] || ! check_com -c cdrecord; then
+ if check_com -c wodim; then
+ cdrecord() {
+ cat <<EOMESS
+cdrecord is not provided under its original name by Debian anymore.
+See #377109 in the BTS of Debian for more details.
+
+Please use the wodim binary instead
+EOMESS
+ return 1
+ }
+ fi
+fi
+
+# Use hard limits, except for a smaller stack and no core dumps
+unlimit
+is425 && limit stack 8192
+isgrmlcd && limit core 0 # important for a live-cd-system
+limit -s
+
+# completion system
+
+# called later (via is4 && grmlcomp)
+# note: use 'zstyle' for getting current settings
+# press ^xh (control-x h) for getting tags in context; ^x? (control-x ?) to run complete_debug with trace output
+grmlcomp() {
+ # TODO: This could use some additional information
+
+ # allow one error for every three characters typed in approximate completer
+ zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
+
+ # don't complete backup files as executables
+ zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)'
+
+ # start menu completion only if it could find no unambiguous initial string
+ zstyle ':completion:*:correct:*' insert-unambiguous true
+ zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
+ zstyle ':completion:*:correct:*' original true
+
+ # activate color-completion
+ zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
+
+ # format on completion
+ zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
+
+ # automatically complete 'cd -<tab>' and 'cd -<ctrl-d>' with menu
+ # zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
+
+ # insert all expansions for expand completer
+ zstyle ':completion:*:expand:*' tag-order all-expansions
+ zstyle ':completion:*:history-words' list false
+
+ # activate menu
+ zstyle ':completion:*:history-words' menu yes
+
+ # ignore duplicate entries
+ zstyle ':completion:*:history-words' remove-all-dups yes
+ zstyle ':completion:*:history-words' stop yes
+
+ # 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
+
+ # 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[@]"
+ grml.org
+ 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
+}
+
+# grmlstuff
+grmlstuff() {
+# people should use 'grml-x'!
+ if check_com -c 915resolution; then
+ 855resolution() {
+ echo "Please use 915resolution as resolution modifying tool for Intel \
+graphic chipset."
+ return -1
+ }
+ fi
+
+ #a1# Output version of running grml
+ alias grml-version='cat /etc/grml_version'
+
+ if check_com -c rebuildfstab ; then
+ #a1# Rebuild /etc/fstab
+ alias grml-rebuildfstab='rebuildfstab -v -r -config'
+ fi
+
+ if check_com -c grml-debootstrap ; then
+ debian2hd() {
+ echo "Installing debian to harddisk is possible by using grml-debootstrap."
+ return 1
+ }
+ fi
+}
+
+# now run the functions
+isgrml && checkhome
+is4 && isgrml && grmlstuff
+is4 && grmlcomp
+
+# keephack
+is4 && xsource "/etc/zsh/keephack"
+
+# wonderful idea of using "e" glob qualifier by Peter Stephenson
+# You use it as follows:
+# $ NTREF=/reference/file