+}
+zle -N 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
+
+### 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
+
+#f5# Create directory under cursor or the selected area
+inplaceMkDirs() {
+ # Press ctrl-xM to create the directory under the cursor or the selected area.
+ # To select an area press ctrl-@ or ctrl-space and use the cursor.
+ # Use case: you type "mv abc ~/testa/testb/testc/" and remember that the
+ # directory does not exist yet -> press ctrl-XM and problem solved
+ local PATHTOMKDIR
+ if ((REGION_ACTIVE==1)); then
+ local F=$MARK T=$CURSOR
+ if [[ $F -gt $T ]]; then
+ F=${CURSOR}
+ T=${MARK}
+ fi
+ # get marked area from buffer and eliminate whitespace
+ PATHTOMKDIR=${BUFFER[F+1,T]%%[[:space:]]##}
+ PATHTOMKDIR=${PATHTOMKDIR##[[:space:]]##}
+ else
+ local bufwords iword
+ bufwords=(${(z)LBUFFER})
+ iword=${#bufwords}
+ bufwords=(${(z)BUFFER})
+ PATHTOMKDIR="${(Q)bufwords[iword]}"
+ fi
+ [[ -z "${PATHTOMKDIR}" ]] && return 1
+ PATHTOMKDIR=${~PATHTOMKDIR}
+ if [[ -e "${PATHTOMKDIR}" ]]; then
+ zle -M " path already exists, doing nothing"
+ else
+ zle -M "$(mkdir -p -v "${PATHTOMKDIR}")"
+ zle end-of-line
+ fi
+}
+
+#k# mkdir -p <dir> from string under cursor or marked area
+zle -N inplaceMkDirs
+
+#v1# set number of lines to display per page
+HELP_LINES_PER_PAGE=20
+#v1# set location of help-zle cache file
+HELP_ZLE_CACHE_FILE=~/.cache/zsh_help_zle_lines.zsh
+# helper function for help-zle, actually generates the help text
+help_zle_parse_keybindings()
+{
+ emulate -L zsh
+ setopt extendedglob
+ unsetopt ksharrays #indexing starts at 1
+
+ #v1# choose files that help-zle will parse for keybindings
+ ((${+HELPZLE_KEYBINDING_FILES})) || HELPZLE_KEYBINDING_FILES=( /etc/zsh/zshrc ~/.zshrc.pre ~/.zshrc ~/.zshrc.local )
+
+ if [[ -r $HELP_ZLE_CACHE_FILE ]]; then
+ local load_cache=0
+ for f ($HELPZLE_KEYBINDING_FILES) [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1
+ [[ $load_cache -eq 0 ]] && . $HELP_ZLE_CACHE_FILE && return
+ fi
+
+ #fill with default keybindings, possibly to be overwriten in a file later
+ #Note that due to zsh inconsistency on escaping assoc array keys, we encase the key in '' which we will remove later
+ local -A help_zle_keybindings
+ help_zle_keybindings['<Ctrl>@']="set MARK"
+ help_zle_keybindings['<Ctrl>x<Ctrl>j']="vi-join lines"
+ help_zle_keybindings['<Ctrl>x<Ctrl>b']="jump to matching brace"
+ help_zle_keybindings['<Ctrl>x<Ctrl>u']="undo"
+ help_zle_keybindings['<Ctrl>_']="undo"
+ help_zle_keybindings['<Ctrl>x<Ctrl>f<c>']="find <c> in cmdline"
+ help_zle_keybindings['<Ctrl>a']="goto beginning of line"
+ help_zle_keybindings['<Ctrl>e']="goto end of line"
+ help_zle_keybindings['<Ctrl>t']="transpose charaters"
+ help_zle_keybindings['<Alt>t']="transpose words"
+ help_zle_keybindings['<Alt>s']="spellcheck word"
+ help_zle_keybindings['<Ctrl>k']="backward kill buffer"
+ help_zle_keybindings['<Ctrl>u']="forward kill buffer"
+ help_zle_keybindings['<Ctrl>y']="insert previously killed word/string"
+ help_zle_keybindings["<Alt>'"]="quote line"
+ help_zle_keybindings['<Alt>"']="quote from mark to cursor"
+ help_zle_keybindings['<Alt><arg>']="repeat next cmd/char <arg> times (<Alt>-<Alt>1<Alt>0a -> -10 times 'a')"
+ help_zle_keybindings['<Alt>u']="make next word Uppercase"
+ help_zle_keybindings['<Alt>l']="make next word lowercase"
+ help_zle_keybindings['<Ctrl>xd']="preview expansion under cursor"
+ help_zle_keybindings['<Alt>q']="push current CL into background, freeing it. Restore on next CL"
+ help_zle_keybindings['<Alt>.']="insert (and interate through) last word from prev CLs"
+ help_zle_keybindings['<Alt>,']="complete word from newer history (consecutive hits)"
+ help_zle_keybindings['<Alt>m']="repeat last typed word on current CL"
+ help_zle_keybindings['<Ctrl>v']="insert next keypress symbol literally (e.g. for bindkey)"
+ help_zle_keybindings['!!:n*<Tab>']="insert last n arguments of last command"
+ help_zle_keybindings['!!:n-<Tab>']="insert arguments n..N-2 of last command (e.g. mv s s d)"
+ help_zle_keybindings['<Alt>h']="show help/manpage for current command"
+
+ #init global variables
+ unset help_zle_lines help_zle_sln
+ typeset -g -a help_zle_lines
+ typeset -g help_zle_sln=1
+
+ local k v
+ local lastkeybind_desc contents #last description starting with #k# that we found
+ local num_lines_elapsed=0 #number of lines between last description and keybinding
+ #search config files in the order they a called (and thus the order in which they overwrite keybindings)
+ for f in $HELPZLE_KEYBINDING_FILES; do
+ [[ -r "$f" ]] || continue #not readable ? skip it
+ contents="$(<$f)"
+ for cline in "${(f)contents}"; do
+ #zsh pattern: matches lines like: #k# ..............
+ if [[ "$cline" == (#s)[[:space:]]#\#k\#[[:space:]]##(#b)(*)[[:space:]]#(#e) ]]; then
+ lastkeybind_desc="$match[*]"
+ num_lines_elapsed=0
+ #zsh pattern: matches lines that set a keybinding using bindkey or compdef -k
+ # ignores lines that are commentend out
+ # grabs first in '' or "" enclosed string with length between 1 and 6 characters
+ elif [[ "$cline" == [^#]#(bindkey|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*) ]]; then
+ #description prevously found ? description not more than 2 lines away ? keybinding not empty ?
+ if [[ -n $lastkeybind_desc && $num_lines_elapsed -lt 2 && -n $match[1] ]]; then
+ #substitute keybinding string with something readable
+ k=${${${${${${${match[1]/\\e\^h/<Alt><BS>}/\\e\^\?/<Alt><BS>}/\\e\[5~/<PageUp>}/\\e\[6~/<PageDown>}//(\\e|\^\[)/<Alt>}//\^/<Ctrl>}/3~/<Alt><Del>}
+ #put keybinding in assoc array, possibly overwriting defaults or stuff found in earlier files
+ #Note that we are extracting the keybinding-string including the quotes (see Note at beginning)
+ help_zle_keybindings[${k}]=$lastkeybind_desc
+ fi
+ lastkeybind_desc=""
+ else
+ ((num_lines_elapsed++))
+ fi
+ done
+ done
+ unset contents
+ #calculate length of keybinding column
+ local kstrlen=0
+ for k (${(k)help_zle_keybindings[@]}) ((kstrlen < ${#k})) && kstrlen=${#k}
+ #convert the assoc array into preformated lines, which we are able to sort
+ for k v in ${(kv)help_zle_keybindings[@]}; do
+ #pad keybinding-string to kstrlen chars and remove outermost characters (i.e. the quotes)
+ help_zle_lines+=("${(r:kstrlen:)k[2,-2]}${v}")
+ done
+ #sort lines alphabetically
+ help_zle_lines=("${(i)help_zle_lines[@]}")
+ [[ -d ${HELP_ZLE_CACHE_FILE:h} ]] || mkdir -p "${HELP_ZLE_CACHE_FILE:h}"
+ echo "help_zle_lines=(${(q)help_zle_lines[@]})" >| $HELP_ZLE_CACHE_FILE
+ zcompile $HELP_ZLE_CACHE_FILE
+}
+typeset -g help_zle_sln
+typeset -g -a help_zle_lines
+
+# Provides (partially autogenerated) help on keybindings and the zsh line editor
+help-zle()
+{
+ emulate -L zsh
+ unsetopt ksharrays #indexing starts at 1
+ #help lines already generated ? no ? then do it
+ [[ ${+functions[help_zle_parse_keybindings]} -eq 1 ]] && {help_zle_parse_keybindings && unfunction help_zle_parse_keybindings}
+ #already displayed all lines ? go back to the start
+ [[ $help_zle_sln -gt ${#help_zle_lines} ]] && help_zle_sln=1
+ local sln=$help_zle_sln
+ #note that help_zle_sln is a global var, meaning we remember the last page we viewed
+ help_zle_sln=$((help_zle_sln + HELP_LINES_PER_PAGE))
+ zle -M "${(F)help_zle_lines[sln,help_zle_sln-1]}"
+}
+zle -N help-zle
+
+## 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
+ }
+ #m# k CTRL-x\,\,\,S Complete word from GNU screen buffer
+ bindkey -r "^xS"
+ compdef -k _complete_screen_display complete-word '^xS'
+fi
+
+# Load a few more functions and tie them to widgets, so they can be bound:
+
+function zrcautozle() {
+ emulate -L zsh
+ local fnc=$1
+ zrcautoload $fnc && zle -N $fnc
+}
+
+function zrcgotwidget() {
+ (( ${+widgets[$1]} ))
+}
+
+function zrcgotkeymap() {
+ [[ -n ${(M)keymaps:#$1} ]]
+}
+
+zrcautozle insert-files
+zrcautozle edit-command-line
+zrcautozle insert-unicode-char
+if zrcautoload history-search-end; then
+ zle -N history-beginning-search-backward-end history-search-end
+ zle -N history-beginning-search-forward-end history-search-end
+fi
+zle -C hist-complete complete-word _generic
+zstyle ':completion:hist-complete:*' completer _history
+
+# The actual terminal setup hooks and bindkey-calls:
+
+# An array to note missing features to ease diagnosis in case of problems.
+typeset -ga grml_missing_features
+
+function zrcbindkey() {
+ if (( ARGC )) && zrcgotwidget ${argv[-1]}; then
+ bindkey "$@"
+ fi
+}
+
+function bind2maps () {
+ local i sequence widget
+ local -a maps
+
+ while [[ "$1" != "--" ]]; do
+ maps+=( "$1" )
+ shift
+ done
+ shift
+
+ sequence="${key[$1]}"
+ widget="$2"
+
+ [[ -z "$sequence" ]] && return 1
+
+ for i in "${maps[@]}"; do
+ zrcbindkey -M "$i" "$sequence" "$widget"
+ done
+}
+
+if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
+ function zle-smkx () {
+ printf '%s' ${terminfo[smkx]}
+ }
+ function zle-rmkx () {
+ printf '%s' ${terminfo[rmkx]}
+ }
+ function zle-line-init () {
+ zle-smkx
+ }
+ function zle-line-finish () {
+ zle-rmkx
+ }
+ zle -N zle-line-init
+ zle -N zle-line-finish
+else
+ for i in {s,r}mkx; do
+ (( ${+terminfo[$i]} )) || grml_missing_features+=($i)
+ done
+ unset i
+fi
+
+typeset -A key
+key=(
+ Home "${terminfo[khome]}"
+ End "${terminfo[kend]}"
+ Insert "${terminfo[kich1]}"
+ Delete "${terminfo[kdch1]}"
+ Up "${terminfo[kcuu1]}"
+ Down "${terminfo[kcud1]}"
+ Left "${terminfo[kcub1]}"
+ Right "${terminfo[kcuf1]}"
+ PageUp "${terminfo[kpp]}"
+ PageDown "${terminfo[knp]}"
+ BackTab "${terminfo[kcbt]}"
+)
+
+bind2maps emacs -- Home beginning-of-somewhere
+bind2maps viins vicmd -- Home vi-beginning-of-line
+bind2maps emacs -- End end-of-somewhere
+bind2maps viins vicmd -- End vi-end-of-line
+bind2maps emacs viins -- Insert overwrite-mode
+bind2maps vicmd -- Insert vi-insert
+bind2maps emacs -- Delete delete-char
+bind2maps viins vicmd -- Delete vi-delete-char
+bind2maps emacs viins vicmd -- Up up-line-or-search
+bind2maps emacs viins vicmd -- Down down-line-or-search
+bind2maps emacs -- Left backward-char
+bind2maps viins vicmd -- Left vi-backward-char
+bind2maps emacs -- Right forward-char
+bind2maps viins vicmd -- Right vi-forward-char
+bind2maps viins vicmd -- Right vi-forward-char
+
+if zrcgotkeymap menuselect; then
+ #m# k Shift-tab Perform backwards menu completion
+ bind2maps menuselect -- BackTab reverse-menu-complete
+
+ #k# menu selection: pick item but stay in the menu
+ zrcbindkey -M menuselect '\e^M' accept-and-menu-complete
+ # also use + and INSERT since it's easier to press repeatedly
+ zrcbindkey -M menuselect "+" accept-and-menu-complete
+ zrcbindkey -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
+ zrcbindkey -M menuselect '^o' accept-and-infer-next-history
+fi
+
+#k# Display list of abbreviations that expand when followed by ,.
+zrcbindkey ",." zleiab
+zrcbindkey '^xb' help-show-abk
+zrcbindkey '^xM' inplaceMkDirs
+#k# display help for keybindings and ZLE
+zrcbindkey '^xz' help-zle
+
+#k# Insert files and test globbing
+zrcbindkey "^xf" insert-files # C-x-f
+
+#k# Edit the current line in \kbd{\$EDITOR}
+zrcbindkey '\ee' edit-command-line
+
+## use Ctrl-left-arrow and Ctrl-right-arrow for jumping to word-beginnings on the CL
+zrcbindkey "\e[5C" forward-word
+zrcbindkey "\e[5D" backward-word
+zrcbindkey "\e[1;5C" forward-word
+zrcbindkey "\e[1;5D" backward-word
+## the same for alt-left-arrow and alt-right-arrow
+zrcbindkey '^[[1;3C' forward-word
+zrcbindkey '^[[1;3D' backward-word
+
+#k# search history backward for entry beginning with typed text
+zrcbindkey '^xp' history-beginning-search-backward-end
+#k# search history forward for entry beginning with typed text
+zrcbindkey '^xP' history-beginning-search-forward-end
+#k# search history backward for entry beginning with typed text
+zrcbindkey "\e[5~" history-beginning-search-backward-end # PageUp
+#k# search history forward for entry beginning with typed text
+zrcbindkey "\e[6~" history-beginning-search-forward-end # PageDown
+
+# 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
+#k# Insert Unicode character
+zrcbindkey '^xi' insert-unicode-char
+
+#k# Toggle abbreviation expansion on/off
+zrcbindkey '^xA' grml_toggle_abbrev
+zrcbindkey "^x^h" commit-to-history
+
+#k# Kill left-side word or everything up to next slash
+zrcbindkey '\ev' slash-backward-kill-word
+#k# Kill left-side word or everything up to next slash
+zrcbindkey '\e^h' slash-backward-kill-word
+#k# Kill left-side word or everything up to next slash
+zrcbindkey '\e^?' slash-backward-kill-word
+
+# use the new *-pattern-* widgets for incremental history search
+if zrcgotwidget history-incremental-pattern-search-backward; then
+ zrcbindkey '^r' history-incremental-pattern-search-backward
+ zrcbindkey '^s' history-incremental-pattern-search-forward
+fi
+
+# Do history expansion on space:
+zrcbindkey ' ' magic-space
+#k# Trigger menu-complete
+zrcbindkey '\ei' menu-complete # menu completion via esc-i
+#k# Insert a timestamp on the command line (yyyy-mm-dd)
+zrcbindkey '^ed' insert-datestamp
+#k# Insert last typed word
+zrcbindkey "\em" insert-last-typed-word
+#k# A smart shortcut for \kbd{fg<enter>}
+zrcbindkey '^z' grml-zsh-fg
+#k# prepend the current command with "sudo"
+zrcbindkey "^os" sudo-command-line
+#k# jump to after first word (for adding options)
+zrcbindkey '^x1' jump_after_first_word
+#k# complete word from history with menu
+zrcbindkey "^x^x" hist-complete
+
+# autoloading
+
+zrcautoload zmv
+zrcautoload zed
+
+# 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
+
+# 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
+}
+
+# history
+
+ZSHDIR=${ZDOTDIR:-${HOME}/.zsh}
+
+#v#
+HISTFILE=${ZDOTDIR:-${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:-${ZDOTDIR:-${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
+
+# Prompt setup for grml:
+
+# set colors for use in prompts (modern zshs allow for the use of %F{red}foo%f
+# in prompts to get a red "foo" embedded, but it's good to keep these for
+# backwards compatibility).
+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_COLOR="%{${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_COLOR=$'%{\e[0m%}'
+fi
+
+# First, the easy ones: PS2..4:
+
+# 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:%_> '
+
+# Some additional features to use with our prompt:
+#
+# - battery status
+# - debian_chroot
+# - vcs_info setup and version specific fixes
+
+# 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 variable debian_chroot if running in a chroot with /etc/debian_chroot
+if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
+ debian_chroot=$(</etc/debian_chroot)
+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 colors:
+ zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOR} " \
+ "zsh: %r"
+ zstyle ':vcs_info:*' formats "${MAGENTA}(${NO_COLOR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOR}%} " \
+ "zsh: %r"
+ zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YELLOW}%r"
+fi
+
+# Now for the fun part: The grml prompt themes in `promptsys' mode of operation
+
+# This actually defines three prompts:
+#
+# - grml
+# - grml-large
+# - grml-chroot
+#
+# They all share the same code and only differ with respect to which items they
+# contain. The main source of documentation is the `prompt_grml_help' function
+# below, which gets called when the user does this: prompt -h grml
+
+function prompt_grml_help () {
+ cat <<__EOF0__
+ prompt grml
+
+ This is the prompt as used by the grml-live system <http://grml.org>. It is
+ a rather simple one-line prompt, that by default looks something like this:
+
+ <user>@<host> <current-working-directory>[ <vcs_info-data>]%
+
+ The prompt itself integrates with zsh's prompt themes system (as you are
+ witnessing right now) and is configurable to a certain degree. In
+ particular, these aspects are customisable:
+
+ - The items used in the prompt (e.g. you can remove \`user' from
+ the list of activated items, which will cause the user name to
+ be omitted from the prompt string).
+
+ - The attributes used with the items are customisable via strings
+ used before and after the actual item.
+
+ The available items are: at, battery, change-root, date, grml-chroot,
+ history, host, jobs, newline, path, percent, rc, rc-always, sad-smiley,
+ shell-level, time, user, vcs
+
+ The actual configuration is done via zsh's \`zstyle' mechanism. The
+ context, that is used while looking up styles is:
+
+ ':prompt:grml:<left-or-right>:<subcontext>'
+
+ Here <left-or-right> is either \`left' or \`right', signifying whether the
+ style should affect the left or the right prompt. <subcontext> is either
+ \`setup' or 'items:<item>', where \`<item>' is one of the available items.
+
+ The styles:
+
+ - use-rprompt (boolean): If \`true' (the default), print a sad smiley
+ in $RPROMPT if the last command a returned non-successful error code.
+ (This in only valid if <left-or-right> is "right"; ignored otherwise)
+
+ - items (list): The list of items used in the prompt. If \`vcs' is
+ present in the list, the theme's code invokes \`vcs_info'
+ accordingly. Default (left): rc change-root user at host path vcs
+ percent; Default (right): sad-smiley
+
+ Available styles in 'items:<item>' are: pre, post. These are strings that
+ are inserted before (pre) and after (post) the item in question. Thus, the
+ following would cause the user name to be printed in red instead of the
+ default blue:
+
+ zstyle ':prompt:grml:*:items:user' pre '%F{red}'
+
+ Note, that the \`post' style may remain at its default value, because its
+ default value is '%f', which turns the foreground text attribute off (which
+ is exactly, what is still required with the new \`pre' value).
+__EOF0__
+}
+
+function prompt_grml-chroot_help () {
+ cat <<__EOF0__
+ prompt grml-chroot
+
+ This is a variation of the grml prompt, see: prompt -h grml
+
+ The main difference is the default value of the \`items' style. The rest
+ behaves exactly the same. Here are the defaults for \`grml-chroot':
+
+ - left: grml-chroot user at host path percent
+ - right: (empty list)
+__EOF0__
+}
+
+function prompt_grml-large_help () {
+ cat <<__EOF0__
+ prompt grml-large
+
+ This is a variation of the grml prompt, see: prompt -h grml
+
+ The main difference is the default value of the \`items' style. In
+ particular, this theme uses _two_ lines instead of one with the plain
+ \`grml' theme. The rest behaves exactly the same. Here are the defaults
+ for \`grml-large':
+
+ - left: rc jobs history shell-level change-root time date newline user
+ at host path vcs percent
+ - right: sad-smiley
+__EOF0__
+}
+
+function grml_prompt_setup () {
+ emulate -L zsh
+ autoload -Uz vcs_info
+ autoload -Uz add-zsh-hook
+ add-zsh-hook precmd prompt_$1_precmd
+}
+
+function prompt_grml_setup () {
+ grml_prompt_setup grml
+}
+
+function prompt_grml-chroot_setup () {
+ grml_prompt_setup grml-chroot
+}
+
+function prompt_grml-large_setup () {
+ grml_prompt_setup grml-large
+}