zshrc: update function swspeak for new script swspeak-setup
[grml-etc-core.git] / etc / zsh / zshrc
1 # Filename:      zshrc
2 # Purpose:       config file for zsh (z shell)
3 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports:   see http://grml.org/bugs/
5 # License:       This file is licensed under the GPL v2.
6 ################################################################################
7 # This file is sourced only for interactive shells. It
8 # should contain commands to set up aliases, functions,
9 # options, key bindings, etc.
10 #
11 # Global Order: zshenv, zprofile, zshrc, zlogin
12 ################################################################################
13
14 # zsh-refcard-tag documentation: {{{
15 #   You may notice strange looking comments in the zshrc (and ~/.zshrc as
16 #   well). These are there for a purpose. grml's zsh-refcard can now be
17 #   automatically generated from the contents of the actual configuration
18 #   files. However, we need a little extra information on which comments
19 #   and what lines of code to take into account (and for what purpose).
20 #
21 # Here is what they mean:
22 #
23 # List of tags (comment types) used:
24 #   #a#     Next line contains an important alias, that should
25 #           be included in the grml-zsh-refcard.
26 #           (placement tag: @@INSERT-aliases@@)
27 #   #f#     Next line contains the beginning of an important function.
28 #           (placement tag: @@INSERT-functions@@)
29 #   #v#     Next line contains an important variable.
30 #           (placement tag: @@INSERT-variables@@)
31 #   #k#     Next line contains an important keybinding.
32 #           (placement tag: @@INSERT-keybindings@@)
33 #   #d#     Hashed directories list generation:
34 #               start   denotes the start of a list of 'hash -d'
35 #                       definitions.
36 #               end     denotes its end.
37 #           (placement tag: @@INSERT-hasheddirs@@)
38 #   #A#     Abbreviation expansion list generation:
39 #               start   denotes the beginning of abbreviations.
40 #               end     denotes their end.
41 #           Lines within this section that end in '#d .*' provide
42 #           extra documentation to be included in the refcard.
43 #           (placement tag: @@INSERT-abbrev@@)
44 #   #m#     This tag allows you to manually generate refcard entries
45 #           for code lines that are hard/impossible to parse.
46 #               Example:
47 #                   #m# k ESC-h Call the run-help function
48 #               That would add a refcard entry in the keybindings table
49 #               for 'ESC-h' with the given comment.
50 #           So the syntax is: #m# <section> <argument> <comment>
51 #   #o#     This tag lets you insert entries to the 'other' hash.
52 #           Generally, this should not be used. It is there for
53 #           things that cannot be done easily in another way.
54 #           (placement tag: @@INSERT-other-foobar@@)
55 #
56 #   All of these tags (except for m and o) take two arguments, the first
57 #   within the tag, the other after the tag:
58 #
59 #   #<tag><section># <comment>
60 #
61 #   Where <section> is really just a number, which are defined by the
62 #   @secmap array on top of 'genrefcard.pl'. The reason for numbers
63 #   instead of names is, that for the reader, the tag should not differ
64 #   much from a regular comment. For zsh, it is a regular comment indeed.
65 #   The numbers have got the following meanings:
66 #         0 -> "default"
67 #         1 -> "system"
68 #         2 -> "user"
69 #         3 -> "debian"
70 #         4 -> "search"
71 #         5 -> "shortcuts"
72 #         6 -> "services"
73 #
74 #   So, the following will add an entry to the 'functions' table in the
75 #   'system' section, with a (hopefully) descriptive comment:
76 #       #f1# Edit an alias via zle
77 #       edalias() {
78 #
79 #   It will then show up in the @@INSERT-aliases-system@@ replacement tag
80 #   that can be found in 'grml-zsh-refcard.tex.in'.
81 #   If the section number is omitted, the 'default' section is assumed.
82 #   Furthermore, in 'grml-zsh-refcard.tex.in' @@INSERT-aliases@@ is
83 #   exactly the same as @@INSERT-aliases-default@@. If you want a list of
84 #   *all* aliases, for example, use @@INSERT-aliases-all@@.
85 #}}}
86
87 # zsh profiling {{{
88 # just execute 'ZSH_PROFILE_RC=1 zsh' and run 'zprof' to get the details
89 if [[ $ZSH_PROFILE_RC -gt 0 ]] ; then
90     zmodload zsh/zprof
91 fi
92 # }}}
93
94 # setting some default values {{{
95 NOCOR=${NOCOR:-0}
96 NOMENU=${NOMENU:-0}
97 NOPRECMD=${NOPRECMD:-0}
98 BATTERY=${BATTERY:-0}
99 # }}}
100
101 # {{{ check for version/system
102 # check for versions (compatibility reasons)
103 is4(){
104     [[ $ZSH_VERSION == <4->* ]] && return 0
105     return 1
106 }
107
108 is41(){
109     [[ $ZSH_VERSION == 4.<1->* || $ZSH_VERSION == <5->* ]] && return 0
110     return 1
111 }
112
113 is42(){
114     [[ $ZSH_VERSION == 4.<2->* || $ZSH_VERSION == <5->* ]] && return 0
115     return 1
116 }
117
118 is425(){
119     [[ $ZSH_VERSION == 4.2.<5->* || $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
120     return 1
121 }
122
123 is43(){
124     [[ $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
125     return 1
126 }
127
128 #f1# Checks whether or not you're running grml
129 isgrml(){
130     [[ -f /etc/grml_version ]] && return 0
131     return 1
132 }
133
134 #f1# Checks whether or not you're running a grml cd
135 isgrmlcd(){
136     [[ -f /etc/grml_cd ]] && return 0
137     return 1
138 }
139
140 if isgrml ; then
141 #f1# Checks whether or not you're running grml-small
142     isgrmlsmall() {
143         [[ ${${${(f)"$(</etc/grml_version)"}%% *}##*-} == 'small' ]] && return 0 ; return 1
144     }
145 else
146     isgrmlsmall() { return 1 }
147 fi
148
149 #f1# are we running within an utf environment?
150 isutfenv() {
151     case "$LANG $CHARSET $LANGUAGE" in
152         *utf*) return 0 ;;
153         *UTF*) return 0 ;;
154         *)     return 1 ;;
155     esac
156 }
157
158 # check for user, if not running as root set $SUDO to sudo
159 (( EUID != 0 )) && SUDO='sudo' || SUDO=''
160
161 # change directory to home on first invocation of zsh
162 # important for rungetty -> autologin
163 # Thanks go to Bart Schaefer!
164 isgrml && checkhome() {
165     if [[ -z "$ALREADY_DID_CD_HOME" ]] ; then
166         export ALREADY_DID_CD_HOME=$HOME
167         cd
168     fi
169 }
170
171 # check for zsh v3.1.7+
172
173 if ! [[ ${ZSH_VERSION} == 3.1.<7->*      \
174      || ${ZSH_VERSION} == 3.<2->.<->*    \
175      || ${ZSH_VERSION} == <4->.<->*   ]] ; then
176
177     printf '-!-\n'
178     printf '-!- In this configuration we try to make use of features, that only\n'
179     printf '-!- require version 3.1.7 of the shell; That way this setup can be\n'
180     printf '-!- used with a wide range of zsh versions, while using fairly\n'
181     printf '-!- advanced features in all supported versions.\n'
182     printf '-!-\n'
183     printf '-!- However, you are running zsh version %s.\n' "$ZSH_VERSION"
184     printf '-!-\n'
185     printf '-!- While this *may* work, it might as well fail.\n'
186     printf '-!- Please consider updating to at least version 3.1.7 of zsh.\n'
187     printf '-!-\n'
188     printf '-!- DO NOT EXPECT THIS TO WORK FLAWLESSLY!\n'
189     printf '-!- If it does today, you'\''ve been lucky.\n'
190     printf '-!-\n'
191     printf '-!- Ye been warned!\n'
192     printf '-!-\n'
193
194     function zstyle() { : }
195 fi
196
197 # }}}
198
199 # utility functions {{{
200 # this function checks if a command exists and returns either true
201 # or false. This avoids using 'which' and 'whence', which will
202 # avoid problems with aliases for which on certain weird systems. :-)
203 check_com() {
204     local -i comonly
205
206     if [[ ${1} == '-c' ]] ; then
207         (( comonly = 1 ))
208         shift
209     else
210         (( comonly = 0 ))
211     fi
212
213     if (( ${#argv} != 1 )) ; then
214         printf 'usage: check_com [-c] <command>\n' >&2
215         return 1
216     fi
217
218     if (( comonly > 0 )) ; then
219         [[ -n ${commands[$1]}  ]] && return 0
220         return 1
221     fi
222
223     if   [[ -n ${commands[$1]}    ]] \
224       || [[ -n ${functions[$1]}   ]] \
225       || [[ -n ${aliases[$1]}     ]] \
226       || [[ -n ${reswords[(r)$1]} ]] ; then
227
228         return 0
229     fi
230
231     return 1
232 }
233
234 # creates an alias and precedes the command with
235 # sudo if $EUID is not zero.
236 salias() {
237     local only=0 ; local multi=0
238     while [[ ${1} == -* ]] ; do
239         case ${1} in
240             (-o) only=1 ;;
241             (-a) multi=1 ;;
242             (--) shift ; break ;;
243             (-h)
244                 printf 'usage: salias [-h|-o|-a] <alias-expression>\n'
245                 printf '  -h      shows this help text.\n'
246                 printf '  -a      replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n'
247                 printf '          be careful using this option.\n'
248                 printf '  -o      only sets an alias if a preceding sudo would be needed.\n'
249                 return 0
250                 ;;
251             (*) printf "unkown option: '%s'\n" "${1}" ; return 1 ;;
252         esac
253         shift
254     done
255
256     if (( ${#argv} > 1 )) ; then
257         printf 'Too many arguments %s\n' "${#argv}"
258         return 1
259     fi
260
261     key="${1%%\=*}" ;  val="${1#*\=}"
262     if (( EUID == 0 )) && (( only == 0 )); then
263         alias -- "${key}=${val}"
264     elif (( EUID > 0 )) ; then
265         (( multi > 0 )) && val="${val// ; / ; sudo }"
266         alias -- "${key}=sudo ${val}"
267     fi
268
269     return 0
270 }
271
272 # a "print -l ${(u)foo}"-workaround for pre-4.2.0 shells
273 # usage: uprint foo
274 #   Where foo is the *name* of the parameter you want printed.
275 #   Note that foo is no typo; $foo would be wrong here!
276 if ! is42 ; then
277     uprint () {
278         local -a u
279         local w
280         local parameter=${1}
281
282         if [[ -z ${parameter} ]] ; then
283             printf 'usage: uprint <parameter>\n'
284             return 1
285         fi
286
287         for w in ${(P)parameter} ; do
288             [[ -z ${(M)u:#${w}} ]] && u=( ${u} ${w} )
289         done
290
291         builtin print -l ${u}
292     }
293 fi
294
295 # Check if we can read given files and source those we can.
296 xsource() {
297     if (( ${#argv} < 1 )) ; then
298         printf 'usage: xsource FILE(s)...\n' >&2
299         return 1
300     fi
301
302     while (( ${#argv} > 0 )) ; do
303         [[ -r ${1} ]] && source ${1}
304         shift
305     done
306     return 0
307 }
308
309 # Check if we can read a given file and 'cat(1)' it.
310 xcat() {
311     if (( ${#argv} != 1 )) ; then
312         printf 'usage: xcat FILE\n' >&2
313         return 1
314     fi
315
316     [[ -r ${1} ]] && cat ${1}
317     return 0
318 }
319
320 # Remove these functions again, they are of use only in these
321 # setup files. This should be called at the end of .zshrc.
322 xunfunction() {
323     local -a funcs
324     funcs=(salias xcat xsource xunfunction zrcautoload)
325
326     for func in $funcs ; do
327         [[ -n ${functions[$func]} ]] \
328             && unfunction $func
329     done
330     return 0
331 }
332
333 # autoload wrapper - use this one instead of autoload directly
334 function zrcautoload() {
335     setopt local_options extended_glob
336     local fdir ffile
337     local -i ffound
338
339     ffile=${1}
340     (( found = 0 ))
341     for fdir in ${fpath} ; do
342         [[ -e ${fdir}/${ffile} ]] && (( ffound = 1 ))
343     done
344
345     (( ffound == 0 )) && return 1
346     if [[ $ZSH_VERSION == 3.1.<6-> || $ZSH_VERSION == <4->* ]] ; then
347         autoload -U ${ffile} || return 1
348     else
349         autoload ${ffile} || return 1
350     fi
351     return 0
352 }
353
354 #}}}
355
356 # Load is-at-least() for more precise version checks {{{
357
358 # Note that this test will *always* fail, if the is-at-least
359 # function could not be marked for autoloading.
360 zrcautoload is-at-least || is-at-least() { return 1 }
361
362 # }}}
363
364 # locale setup {{{
365 if [[ -z "$LANG" ]] ; then
366    xsource "/etc/default/locale"
367 fi
368
369 export LANG=${LANG:-en_US.iso885915}
370 for var in LC_ALL LC_MESSAGES ; do
371     [[ -n ${(P)var} ]] && export $var
372 done
373
374 xsource "/etc/sysconfig/keyboard"
375
376 TZ=$(xcat /etc/timezone)
377 # }}}
378
379 # check for potentially old files in 'completion.d' {{{
380 setopt extendedglob
381 xof=(/etc/zsh/completion.d/*~/etc/zsh/completion.d/_*(N))
382 if (( ${#xof} > 0 )) ; then
383     printf '\n -!- INFORMATION\n\n'
384     printf ' -!- %s file(s) not starting with an underscore (_) found in\n' ${#xof}
385     printf ' -!- /etc/zsh/completion.d/.\n\n'
386     printf ' -!- While this has been the case in old versions of grml-etc-core,\n'
387     printf ' -!- recent versions of the grml-zsh-setup have all these files rewritten\n'
388     printf ' -!- and renamed. Furthermore, the grml-zsh-setup will *only* add files\n'
389     printf ' -!- named _* to that directory.\n\n'
390     printf ' -!- If you added functions to completion.d yourself, please consider\n'
391     printf ' -!- moving them to /etc/zsh/functions.d/. Files in that directory, not\n'
392     printf ' -!- starting with an underscore are marked for automatic loading\n'
393     printf ' -!- by default (so that is quite convenient).\n\n'
394     printf ' -!- If there are files *not* starting with an underscore from an older\n'
395     printf ' -!- grml-etc-core in completion.d, you may safely remove them.\n\n'
396     printf ' -!- Delete the files for example via running:\n\n'
397     printf "      rm ${xof}\n\n"
398     printf ' -!- Note, that this message will *not* go away, unless you yourself\n'
399     printf ' -!- resolve the situation manually.\n\n'
400     BROKEN_COMPLETION_DIR=1
401 fi
402 unset xof
403 # }}}
404
405 # {{{ set some variables
406 if check_com -c vim ; then
407 #v#
408     export EDITOR=${EDITOR:-vim}
409 else
410     export EDITOR=${EDITOR:-vi}
411 fi
412
413 #v#
414 export PAGER=${PAGER:-less}
415
416 #v#
417 export MAIL=${MAIL:-/var/mail/$USER}
418
419 # if we don't set $SHELL then aterm, rxvt,.. will use /bin/sh or /bin/bash :-/
420 export SHELL='/bin/zsh'
421
422 # color setup for ls:
423 check_com -c dircolors && eval $(dircolors -b)
424
425 # set width of man pages to 80 for more convenient reading
426 # export MANWIDTH=${MANWIDTH:-80}
427
428 # Search path for the cd command
429 #  cdpath=(.. ~)
430
431 # completion functions go to /etc/zsh/completion.d
432 # function files may be put into /etc/zsh/functions.d, from where they
433 # will be automatically autoloaded.
434 if [[ -n "$BROKEN_COMPLETION_DIR" ]] ; then
435     print 'Warning: not setting completion directories because broken files have been found.' >&2
436 else
437     [[ -d /etc/zsh/completion.d ]] && fpath=( $fpath /etc/zsh/completion.d )
438     if [[ -d /etc/zsh/functions.d ]] ; then
439         fpath+=( /etc/zsh/functions.d )
440         for func in /etc/zsh/functions.d/[^_]*[^~](N.) ; do
441             zrcautoload -U ${func:t}
442         done
443     fi
444 fi
445
446 # automatically remove duplicates from these arrays
447 typeset -U path cdpath fpath manpath
448 # }}}
449
450 # {{{ keybindings
451 if [[ "$TERM" != emacs ]] ; then
452     [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
453     [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
454     [[ -z "$terminfo[kend]"  ]] || bindkey -M emacs "$terminfo[kend]"  end-of-line
455     [[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
456     [[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
457     [[ -z "$terminfo[kend]"  ]] || bindkey -M vicmd "$terminfo[kend]"  vi-end-of-line
458     [[ -z "$terminfo[cuu1]"  ]] || bindkey -M viins "$terminfo[cuu1]"  vi-up-line-or-history
459     [[ -z "$terminfo[cuf1]"  ]] || bindkey -M viins "$terminfo[cuf1]"  vi-forward-char
460     [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
461     [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
462     [[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
463     [[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
464     # ncurses stuff:
465     [[ "$terminfo[kcuu1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
466     [[ "$terminfo[kcud1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
467     [[ "$terminfo[kcuf1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
468     [[ "$terminfo[kcub1]" == $'\eO'* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
469     [[ "$terminfo[khome]" == $'\eO'* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
470     [[ "$terminfo[kend]"  == $'\eO'* ]] && bindkey -M viins "${terminfo[kend]/O/[}"  end-of-line
471     [[ "$terminfo[khome]" == $'\eO'* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
472     [[ "$terminfo[kend]"  == $'\eO'* ]] && bindkey -M emacs "${terminfo[kend]/O/[}"  end-of-line
473 fi
474
475 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
476 # use emacs style per default:
477 bindkey -e
478 # use vi style:
479 # bindkey -v
480
481 #if [[ "$TERM" == screen ]] ; then
482 bindkey '\e[1~' beginning-of-line       # home
483 bindkey '\e[4~' end-of-line             # end
484 bindkey '\e[A'  up-line-or-search       # cursor up
485 bindkey '\e[B'  down-line-or-search     # <ESC>-
486
487 bindkey '^xp'   history-beginning-search-backward
488 bindkey '^xP'   history-beginning-search-forward
489 # bindkey -s '^L' "|less\n"             # ctrl-L pipes to less
490 # bindkey -s '^B' " &\n"                # ctrl-B runs it in the background
491 # if terminal type is set to 'rxvt':
492 bindkey '\e[7~' beginning-of-line       # home
493 bindkey '\e[8~' end-of-line             # end
494 #fi
495
496 # insert unicode character
497 # usage example: 'ctrl-x i' 00A7 'ctrl-x i' will give you an Â§
498 # See for example http://unicode.org/charts/ for unicode characters code
499 zrcautoload insert-unicode-char
500 zle -N insert-unicode-char
501 #k# Insert Unicode character
502 bindkey '^Xi' insert-unicode-char
503
504 # just type 'cd ...' to get 'cd ../..'
505 #  rationalise-dot() {
506 #  if [[ $LBUFFER == *.. ]] ; then
507 #    LBUFFER+=/..
508 #  else
509 #    LBUFFER+=.
510 #  fi
511 #  }
512 #  zle -N rationalise-dot
513 #  bindkey . rationalise-dot
514
515 #  bindkey '\eq' push-line-or-edit
516
517 ## toggle the ,. abbreviation feature on/off
518 # NOABBREVIATION: default abbreviation-state
519 #                 0 - enabled (default)
520 #                 1 - disabled
521 NOABBREVIATION=${NOABBREVIATION:-0}
522
523 grml_toggle_abbrev() {
524     if (( ${NOABBREVIATION} > 0 )) ; then
525         NOABBREVIATION=0
526     else
527         NOABBREVIATION=1
528     fi
529 }
530
531 zle -N grml_toggle_abbrev
532 bindkey '^xA' grml_toggle_abbrev
533
534 # }}}
535
536 # a generic accept-line wrapper {{{
537
538 # This widget can prevent unwanted autocorrections from command-name
539 # to _command-name, rehash automatically on enter and call any number
540 # of builtin and user-defined widgets in different contexts.
541 #
542 # For a broader description, see:
543 # <http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html>
544 #
545 # The code is imported from the file 'zsh/functions/accept-line' from
546 # <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>, which
547 # distributed under the same terms as zsh itself.
548
549 # A newly added command will may not be found or will cause false
550 # correction attempts, if you got auto-correction set. By setting the
551 # following style, we force accept-line() to rehash, if it cannot
552 # find the first word on the command line in the $command[] hash.
553 zstyle ':acceptline:*' rehash true
554
555 function Accept-Line() {
556     setopt localoptions noksharrays
557     local -a subs
558     local -xi aldone
559     local sub
560
561     zstyle -a ":acceptline:${alcontext}" actions subs
562
563     (( ${#subs} < 1 )) && return 0
564
565     (( aldone = 0 ))
566     for sub in ${subs} ; do
567         [[ ${sub} == 'accept-line' ]] && sub='.accept-line'
568         zle ${sub}
569
570         (( aldone > 0 )) && break
571     done
572 }
573
574 function Accept-Line-getdefault() {
575     local default_action
576
577     zstyle -s ":acceptline:${alcontext}" default_action default_action
578     case ${default_action} in
579         ((accept-line|))
580             printf ".accept-line"
581             ;;
582         (*)
583             printf ${default_action}
584             ;;
585     esac
586 }
587
588 function accept-line() {
589     setopt localoptions noksharrays
590     local -a cmdline
591     local -x alcontext
592     local buf com fname format msg default_action
593
594     alcontext='default'
595     buf="${BUFFER}"
596     cmdline=(${(z)BUFFER})
597     com="${cmdline[1]}"
598     fname="_${com}"
599
600     zstyle -t ":acceptline:${alcontext}" rehash \
601         && [[ -z ${commands[$com]} ]]           \
602         && rehash
603
604     if    [[ -n ${reswords[(r)$com]} ]] \
605        || [[ -n ${aliases[$com]}     ]] \
606        || [[ -n ${functions[$com]}   ]] \
607        || [[ -n ${builtins[$com]}    ]] \
608        || [[ -n ${commands[$com]}    ]] ; then
609
610         # there is something sensible to execute, just do it.
611         alcontext='normal'
612         zle Accept-Line
613
614         default_action=$(Accept-Line-getdefault)
615         zstyle -T ":acceptline:${alcontext}" call_default \
616             && zle ${default_action}
617         return
618     fi
619
620     if    [[ -o correct              ]] \
621        || [[ -o correctall           ]] \
622        && [[ -n ${functions[$fname]} ]] ; then
623
624         # nothing there to execute but there is a function called
625         # _command_name; a completion widget. Makes no sense to
626         # call it on the commandline, but the correct{,all} options
627         # will ask for it nevertheless, so warn the user.
628         if [[ ${LASTWIDGET} == 'accept-line' ]] ; then
629             # Okay, we warned the user before, he called us again,
630             # so have it his way.
631             alcontext='force'
632             zle Accept-Line
633
634             default_action=$(Accept-Line-getdefault)
635             zstyle -T ":acceptline:${alcontext}" call_default \
636                 && zle ${default_action}
637             return
638         fi
639
640         # prepare warning message for the user, configurable via zstyle.
641         zstyle -s ":acceptline:${alcontext}" compwarnfmt msg
642
643         if [[ -z ${msg} ]] ; then
644             msg="%c will not execute and completion %f exists."
645         fi
646
647         zformat -f msg "${msg}" "c:${com}" "f:${fname}"
648
649         zle -M -- "${msg}"
650         return
651     elif [[ -n ${buf//[$' \t\n']##/} ]] ; then
652         # If we are here, the commandline contains something that is not
653         # executable, which is neither subject to _command_name correction
654         # and is not empty. might be a variable assignment
655         alcontext='misc'
656         zle Accept-Line
657
658         default_action=$(Accept-Line-getdefault)
659         zstyle -T ":acceptline:${alcontext}" call_default \
660             && zle ${default_action}
661         return
662     fi
663
664     # If we got this far, the commandline only contains whitespace, or is empty.
665     alcontext='empty'
666     zle Accept-Line
667
668     default_action=$(Accept-Line-getdefault)
669     zstyle -T ":acceptline:${alcontext}" call_default \
670         && zle ${default_action}
671 }
672
673 zle -N accept-line
674 zle -N Accept-Line
675
676 # }}}
677
678 # power completion - abbreviation expansion {{{
679 # power completion / abbreviation expansion / buffer expansion
680 # see http://zshwiki.org/home/examples/zleiab for details
681 # less risky than the global aliases but powerful as well
682 # just type the abbreviation key and afterwards ',.' to expand it
683 declare -A abk
684 setopt extendedglob
685 setopt interactivecomments
686 abk=(
687 # key  # value                (#d additional doc string)
688 #A# start
689     '...' '../..'
690     '....' '../../..'
691     'BG' '& exit'
692     'C' '| wc -l'
693     'G' '|& grep --color=auto'
694     'H' '| head'
695     'Hl' ' --help |& less -r'      #d (Display help in pager)
696     'L' '| less'
697     'LL' '|& less -r'
698     'M' '| most'
699     'N' '&>/dev/null'              #d (No Output)
700     'R' '| tr A-z N-za-m'          #d (ROT13)
701     'SL' '| sort | less'
702     'S' '| sort -u'
703     'T' '| tail'
704     'V' '|& vim -'
705 #A# end
706     'hide' "echo -en '\033]50;nil2\007'"
707     'tiny' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-80-*-*-c-*-iso8859-15\007"'
708     'small' 'echo -en "\033]50;6x10\007"'
709     'medium' 'echo -en "\033]50;-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-15\007"'
710     'default' 'echo -e "\033]50;-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-15\007"'
711     'large' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-150-*-*-c-*-iso8859-15\007"'
712     'huge' 'echo -en "\033]50;-misc-fixed-medium-r-normal-*-*-210-*-*-c-*-iso8859-15\007"'
713     'smartfont' 'echo -en "\033]50;-artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*\007"'
714     'semifont' 'echo -en "\033]50;-misc-fixed-medium-r-semicondensed-*-*-120-*-*-*-*-iso8859-15\007"'
715     'da' 'du -sch'
716     'j' 'jobs -l'
717     'u' 'translate -i'
718     'co' "./configure && make && sudo make install"
719     'CH' "./configure --help"
720     'conkeror' 'firefox -chrome chrome://conkeror/content'
721     'dir' 'ls -lSrah'
722     'lad' $'ls -d .*(/)\n# only show dot-directories'
723     'lsa' $'ls -a .*(.)\n# only show dot-files'
724     'lss' $'ls -l *(s,S,t)\n# only files with setgid/setuid/sticky flag'
725     'lsl' $'ls -l *(@[1,10])\n# only symlinks'
726     'lsx' $'ls -l *(*[1,10])\n# only executables'
727     'lsw' $'ls -ld *(R,W,X.^ND/)\n# world-{readable,writable,executable} files'
728     'lsbig' $'ls -flh *(.OL[1,10])\n# display the biggest files'
729     'lsd' $'ls -d *(/)\n# only show directories'
730     'lse' $'ls -d *(/^F)\n# only show empty directories'
731     'lsnew' $'ls -rl *(D.om[1,10])\n# display the newest files'
732     'lsold' $'ls -rtlh *(D.om[-11,-1])\n # display the oldest files'
733     'lssmall' $'ls -Srl *(.oL[1,10])\n# display the smallest files'
734     'rw-' 'chmod 600'
735     '600' 'chmod u+rw-x,g-rwx,o-rwx'
736     'rwx' 'chmod u+rwx'
737     '700' 'chmod u+rwx,g-rwx,o-rwx'
738     'r--' 'chmod u+r-wx,g-rwx,o-rwx'
739     '644' $'chmod u+rw-x,g+r-wx,o+r-wx\n # 4=r,2=w,1=x'
740     '755' 'chmod u+rwx,g+r-w+x,o+r-w+x'
741     'md' 'mkdir -p '
742     'cmplayer' 'mplayer -vo -fs -zoom fbdev'
743     'fbmplayer' 'mplayer -vo -fs -zoom fbdev'
744     'fblinks' 'links2 -driver fb'
745     'insecssh' 'ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
746     'insecscp' 'scp -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile=/dev/null"'
747     'fori' 'for i ({..}) { }'
748     'cx' 'chmod +x'
749     'e'  'print -l'
750     'se' 'setopt interactivecomments'
751     'va' 'valac --vapidir=../vapi/ --pkg=gtk+-2.0 gtktest.vala'
752     'fb2' '=mplayer -vo fbdev -fs -zoom 1>/dev/null -xy 2'
753     'fb3' '=mplayer -vo fbdev -fs  -zoom 1>/dev/null -xy 3'
754     'ci' 'centericq'
755     'D'  'export DISPLAY=:0.0'
756     'mp' 'mplayer -vo xv -fs -zoom'
757 )
758
759 globalias() {
760     local MATCH
761
762     if (( NOABBREVIATION > 0 )) ; then
763         LBUFFER="${LBUFFER},."
764         return 0
765     fi
766
767     matched_chars='[.-|_a-zA-Z0-9]#'
768     LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#}
769     LBUFFER+=${abk[$MATCH]:-$MATCH}
770 }
771
772 zle -N globalias
773 bindkey ",." globalias
774 # }}}
775
776 # {{{ autoloading
777 zrcautoload zmv    # who needs mmv or rename?
778 zrcautoload history-search-end
779
780 # we don't want to quote/espace URLs on our own...
781 # if autoload -U url-quote-magic ; then
782 #    zle -N self-insert url-quote-magic
783 #    zstyle ':url-quote-magic:*' url-metas '*?[]^()~#{}='
784 # else
785 #    print 'Notice: no url-quote-magic available :('
786 # fi
787 alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic'
788
789 #m# k ESC-h Call \kbd{run-help} for the 1st word on the command line
790 alias run-help >&/dev/null && unalias run-help
791 zrcautoload run-help # use via 'esc-h'
792
793 # completion system
794 if zrcautoload compinit && compinit 2>/dev/null ; then
795     compinit 2>/dev/null || print 'Notice: no compinit available :('
796 else
797     print 'Notice: no compinit available :('
798     function zstyle { }
799     function compdef { }
800 fi
801
802 is4 && zrcautoload zed # use ZLE editor to edit a file or function
803
804 is4 && \
805 for mod in complist deltochar mathfunc ; do
806     zmodload -i zsh/${mod} 2>/dev/null || print "Notice: no ${mod} available :("
807 done
808
809 # autoload zsh modules when they are referenced
810 if is4 ; then
811     tmpargs=(
812         a   stat
813         a   zpty
814         ap  mapfile
815     )
816
817     while (( ${#tmpargs} > 0 )) ; do
818         zmodload -${tmpargs[1]} zsh/${tmpargs[2]} ${tmpargs[2]}
819         shift 2 tmpargs
820     done
821     unset tmpargs
822 fi
823
824 if is4 && zrcautoload insert-files && zle -N insert-files ; then
825     #k# Insert files
826     bindkey "^Xf" insert-files # C-x-f
827 fi
828
829 bindkey ' '   magic-space    # also do history expansion on space
830 #k# Trigger menu-complete
831 bindkey '\ei' menu-complete  # menu completion via esc-i
832
833 # press esc-e for editing command line in $EDITOR or $VISUAL
834 if is4 && zrcautoload edit-command-line && zle -N edit-command-line ; then
835     #k# Edit the current line in \kbd{\$EDITOR}
836     bindkey '\ee' edit-command-line
837 fi
838
839 if is4 && [[ -n ${(k)modules[zsh/complist]} ]] ; then
840     #k# menu selection: pick item but stay in the menu
841     bindkey -M menuselect '\e^M' accept-and-menu-complete
842
843     # use the vi navigation keys (hjkl) besides cursor keys in menu completion
844     #bindkey -M menuselect 'h' vi-backward-char        # left
845     #bindkey -M menuselect 'k' vi-up-line-or-history   # up
846     #bindkey -M menuselect 'l' vi-forward-char         # right
847     #bindkey -M menuselect 'j' vi-down-line-or-history # bottom
848
849     # accept a completion and try to complete again by using menu
850     # completion; very useful with completing directories
851     # by using 'undo' one's got a simple file browser
852     bindkey -M menuselect '^o' accept-and-infer-next-history
853 fi
854
855 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
856 _bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
857 zle -N _bkdate
858
859 #k# Insert a timestamp on the command line (yyyy-mm-dd)
860 bindkey '^Ed' _bkdate
861
862 # press esc-m for inserting last typed word again (thanks to caphuso!)
863 insert-last-typed-word() { zle insert-last-word -- 0 -1 };
864 zle -N insert-last-typed-word;
865
866 #k# Insert last typed word
867 bindkey "\em" insert-last-typed-word
868
869 # set command prediction from history, see 'man 1 zshcontrib'
870 #  is4 && zrcautoload predict-on && \
871 #  zle -N predict-on         && \
872 #  zle -N predict-off        && \
873 #  bindkey "^X^Z" predict-on && \
874 #  bindkey "^Z" predict-off
875
876 #k# Shortcut for \kbd{fg<enter>}
877 bindkey -s '^z' "fg\n"
878
879 # press ctrl-q to quote line:
880 #  mquote () {
881 #        zle beginning-of-line
882 #        zle forward-word
883 #        # RBUFFER="'$RBUFFER'"
884 #        RBUFFER=${(q)RBUFFER}
885 #        zle end-of-line
886 #  }
887 #  zle -N mquote && bindkey '^q' mquote
888
889 # run command line as user root via sudo:
890 sudo-command-line() {
891     [[ -z $BUFFER ]] && zle up-history
892     [[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
893 }
894 zle -N sudo-command-line
895
896 #k# Put the current command line into a \kbd{sudo} call
897 bindkey "^Os" sudo-command-line
898
899 ### jump behind the first word on the cmdline.
900 ### useful to add options.
901 function jump_after_first_word() {
902     local words
903     words=(${(z)BUFFER})
904
905     if (( ${#words} <= 1 )) ; then
906         CURSOR=${#BUFFER}
907     else
908         CURSOR=${#${words[1]}}
909     fi
910 }
911 zle -N jump_after_first_word
912
913 bindkey '^x1' jump_after_first_word
914
915 # }}}
916
917 # {{{ set some important options
918 # Please update these tags, if you change the umask settings below.
919 #o# r_umask     002
920 #o# r_umaskstr  rwxrwxr-x
921 #o# umask       022
922 #o# umaskstr    rwxr-xr-x
923 (( EUID != 0 )) && umask 002 || umask 022
924
925 # history:
926 setopt append_history       # append history list to the history file (important for multiple parallel zsh sessions!)
927 is4 && setopt SHARE_HISTORY # import new commands from the history file also in other zsh-session
928 setopt extended_history     # save each command's beginning timestamp and the duration to the history file
929 is4 && setopt histignorealldups # If  a  new  command  line being added to the history
930                             # list duplicates an older one, the older command is removed from the list
931 setopt histignorespace      # remove command lines from the history list when
932                             # the first character on the line is a space
933 #  setopt histallowclobber    # add `|' to output redirections in the history
934 #  setopt NO_clobber          # warning if file exists ('cat /dev/null > ~/.zshrc')
935 setopt auto_cd              # if a command is issued that can't be executed as a normal command,
936                             # and the command is the name of a directory, perform the cd command to that directory
937 setopt extended_glob        # in order to use #, ~ and ^ for filename generation
938                             # grep word *~(*.gz|*.bz|*.bz2|*.zip|*.Z) ->
939                             # -> searches for word not in compressed files
940                             # don't forget to quote '^', '~' and '#'!
941 setopt longlistjobs         # display PID when suspending processes as well
942 setopt notify               # report the status of backgrounds jobs immediately
943 setopt hash_list_all        # Whenever a command completion is attempted, make sure \
944                             # the entire command path is hashed first.
945 setopt completeinword       # not just at the end
946 # setopt nocheckjobs          # don't warn me about bg processes when exiting
947 setopt nohup                # and don't kill them, either
948 # setopt printexitvalue       # alert me if something failed
949 # setopt dvorak               # with spelling correction, assume dvorak kb
950 setopt auto_pushd           # make cd push the old directory onto the directory stack.
951 setopt nonomatch            # try to avoid the 'zsh: no matches found...'
952 setopt nobeep               # avoid "beep"ing
953 setopt pushd_ignore_dups    # don't push the same dir twice.
954
955 MAILCHECK=30       # mailchecks
956 REPORTTIME=5       # report about cpu-/system-/user-time of command if running longer than 5 seconds
957 watch=(notme root) # watch for everyone but me and root
958
959 # define word separators (for stuff like backward-word, forward-word, backward-kill-word,..)
960 #  WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' # the default
961 #  WORDCHARS=.
962 #  WORDCHARS='*?_[]~=&;!#$%^(){}'
963 #  WORDCHARS='${WORDCHARS:s@/@}'
964
965 # only slash should be considered as a word separator:
966 slash-backward-kill-word() {
967     local WORDCHARS="${WORDCHARS:s@/@}"
968     # zle backward-word
969     zle backward-kill-word
970 }
971 zle -N slash-backward-kill-word
972
973 #k# Kill everything in a word up to its last \kbd{/}
974 bindkey '\ev' slash-backward-kill-word
975
976 # }}}
977
978 # {{{ history
979
980 ZSHDIR=$HOME/.zsh
981
982 #v#
983 HISTFILE=$HOME/.zsh_history
984 isgrmlcd && HISTSIZE=500  || HISTSIZE=5000
985 isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history
986
987 # }}}
988
989 # dirstack handling {{{
990
991 DIRSTACKSIZE=${DIRSTACKSIZE:-20}
992 DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs}
993
994 if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
995     dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
996     # "cd -" won't work after login by just setting $OLDPWD, so
997     [[ -d $dirstack[0] ]] && cd $dirstack[0] && cd $OLDPWD
998 fi
999
1000 chpwd() {
1001     if is42 ; then
1002         builtin print -l ${(u)dirstack} >! ${DIRSTACKFILE}
1003     else
1004         uprint dirstack >! ${DIRSTACKFILE}
1005     fi
1006 }
1007
1008 # }}}
1009
1010 # {{{ display battery status on right side of prompt via running 'BATTERY=1 zsh'
1011 if [[ $BATTERY -gt 0 ]] ; then
1012     if ! check_com -c acpi ; then
1013         BATTERY=0
1014     fi
1015 fi
1016
1017 battery() {
1018 if [[ $BATTERY -gt 0 ]] ; then
1019     PERCENT="${${"$(acpi 2>/dev/null)"}/(#b)[[:space:]]##Battery <->: [^0-9]##, (<->)%*/${match[1]}}"
1020     if [[ -z "$PERCENT" ]] ; then
1021         PERCENT='acpi not present'
1022     else
1023         if [[ "$PERCENT" -lt 20 ]] ; then
1024             PERCENT="warning: ${PERCENT}%%"
1025         else
1026             PERCENT="${PERCENT}%%"
1027         fi
1028     fi
1029 fi
1030 }
1031 # }}}
1032
1033 # set colors for use in prompts {{{
1034 if zrcautoload colors && colors 2>/dev/null ; then
1035     BLUE="%{${fg[blue]}%}"
1036     RED="%{${fg_bold[red]}%}"
1037     GREEN="%{${fg[green]}%}"
1038     CYAN="%{${fg[cyan]}%}"
1039     MAGENTA="%{${fg[magenta]}%}"
1040     YELLOW="%{${fg[yellow]}%}"
1041     WHITE="%{${fg[white]}%}"
1042     NO_COLOUR="%{${reset_color}%}"
1043 else
1044     BLUE=$'%{\e[1;34m%}'
1045     RED=$'%{\e[1;31m%}'
1046     GREEN=$'%{\e[1;32m%}'
1047     CYAN=$'%{\e[1;36m%}'
1048     WHITE=$'%{\e[1;37m%}'
1049     MAGENTA=$'%{\e[1;35m%}'
1050     YELLOW=$'%{\e[1;33m%}'
1051     NO_COLOUR=$'%{\e[0m%}'
1052 fi
1053
1054 # }}}
1055
1056 # gather version control information for inclusion in a prompt {{{
1057
1058 if ! is41 ; then
1059     # Be quiet about version problems in grml's zshrc as the user cannot disable
1060     # loading vcs_info() as it is *in* the zshrc - as you can see. :-)
1061     # Just unset most probable variables and disable vcs_info altogether.
1062     local -i i
1063     for i in {0..9} ; do
1064         unset VCS_INFO_message_${i}_
1065     done
1066     zstyle ':vcs_info:*' enable false
1067 fi
1068
1069 # The following code is imported from the file 'zsh/functions/vcs_info'
1070 # from <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>,
1071 # which distributed under the same terms as zsh itself.
1072
1073 # we will only be using one variable, so let the code know now.
1074 zstyle ':vcs_info:*' max-exports 1
1075
1076 # vcs_info() documentation:
1077 #{{{
1078 # REQUIREMENTS:
1079 #{{{
1080 #     This functionality requires zsh version >= 4.1.*.
1081 #}}}
1082 #
1083 # LOADING:
1084 #{{{
1085 # To load vcs_info(), copy this file to your $fpath[] and do:
1086 #   % autoload -Uz vcs_info && vcs_info
1087 #
1088 # To work, vcs_info() needs 'setopt prompt_subst' in your setup.
1089 #}}}
1090 #
1091 # QUICKSTART:
1092 #{{{
1093 # To get vcs_info() working quickly (including colors), you can do the
1094 # following (assuming, you loaded vcs_info() properly - see above):
1095 #
1096 # % RED=$'%{\e[31m%}'
1097 # % GR=$'%{\e[32m%}'
1098 # % MA=$'%{\e[35m%}'
1099 # % YE=$'%{\e[33m%}'
1100 # % NC=$'%{\e[0m%}'
1101 #
1102 # % zstyle ':vcs_info:*' actionformats \
1103 #       "${MA}(${NC}%s${MA})${YE}-${MA}[${GR}%b${YE}|${RED}%a${MA}]${NC} "
1104 #
1105 # % zstyle ':vcs_info:*' formats       \
1106 #       "${MA}(${NC}%s${MA})${Y}-${MA}[${GR}%b${MA}]${NC}%} "
1107 #
1108 # % zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YE}%r"
1109 #
1110 # % precmd () { vcs_info }
1111 # % PS1='${MA}[${GR}%n${MA}] ${MA}(${RED}%!${MA}) ${YE}%3~ ${VCS_INFO_message_0_}${NC}%# '
1112 #
1113 # Obviously, the las two lines are there for demonstration: You need to
1114 # call vcs_info() from your precmd() function (see 'SPECIAL FUNCTIONS' in
1115 # 'man zshmisc'). Once that is done you need a *single* quoted
1116 # '${VCS_INFO_message_0_}' in your prompt.
1117 #
1118 # Now call the 'vcs_info_printsys' utility from the command line:
1119 #
1120 # % vcs_info_printsys
1121 # # list of supported version control backends:
1122 # # disabled systems are prefixed by a hash sign (#)
1123 # git
1124 # hg
1125 # bzr
1126 # darcs
1127 # svk
1128 # mtn
1129 # svn
1130 # cvs
1131 # cdv
1132 # tla
1133 # # flavours (cannot be used in the disable style; they
1134 # # are disabled with their master [git-svn -> git]):
1135 # git-p4
1136 # git-svn
1137 #
1138 # Ten version control backends as you can see. You may not want all
1139 # of these. Because there is no point in running the code to detect
1140 # systems you do not use. ever. So, there is a way to disable some
1141 # backends altogether:
1142 #
1143 # % zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
1144 #
1145 # If you rerun 'vcs_info_printsys' now, you will see the backends listed
1146 # in the 'disable' style marked as diabled by a hash sign. That means the
1147 # detection of these systems is skipped *completely*. No wasted time there.
1148 #
1149 # For more control, read the reference below.
1150 #}}}
1151 #
1152 # CONFIGURATION:
1153 #{{{
1154 # The vcs_info() feature can be configured via zstyle.
1155 #
1156 # First, the context in which we are working:
1157 #       :vcs_info:<vcs-string>:<user-context>
1158 #
1159 # ...where <vcs-string> is one of:
1160 #   - git, git-svn, git-p4, hg, darcs, bzr, cdv, mtn, svn, cvs, svk or tla.
1161 #
1162 # ...and <user-context> is a freely configurable string, assignable by the
1163 # user as the first argument to vcs_info() (see its description below).
1164 #
1165 # There is are three special values for <vcs-string>: The first is named
1166 # 'init', that is in effect as long as there was no decision what vcs
1167 # backend to use. The second is 'preinit; it is used *before* vcs_info()
1168 # is run, when initializing the data exporting variables. The third
1169 # special value is 'formats' and is used by the 'vcs_info_lastmsg' for
1170 # looking up its styles.
1171 #
1172 # There are two pre-defined values for <user-context>:
1173 #   default  - the one used if none is specified
1174 #   command  - used by vcs_info_lastmsg to lookup its styles.
1175 #
1176 # You may *not* use 'print_systems_' as a user-context string, because it
1177 # is used internally.
1178 #
1179 # You can of course use ':vcs_info:*' to match all VCSs in all
1180 # user-contexts at once.
1181 #
1182 # Another special context is 'formats', which is used by the
1183 # vcs_info_lastmsg() utility function (see below).
1184 #
1185 #
1186 # This is a description of all styles, that are looked up:
1187 #   formats             - A list of formats, used when actionformats is not
1188 #                         used (which is most of the time).
1189 #   actionformats       - A list of formats, used if a there is a special
1190 #                         action going on in your current repository;
1191 #                         (like an interactive rebase or a merge conflict)
1192 #   branchformat        - Some backends replace %b in the formats and
1193 #                         actionformats styles above, not only by a branch
1194 #                         name but also by a revision number. This style
1195 #                         let's you modify how that string should look like.
1196 #   nvcsformats         - These "formats" are exported, when we didn't detect
1197 #                         a version control system for the current directory.
1198 #                         This is useful, if you want vcs_info() to completely
1199 #                         take over the generation of your prompt.
1200 #                         You would do something like
1201 #                           PS1='${VCS_INFO_message_0_}'
1202 #                         to accomplish that.
1203 #   max-exports         - Defines the maximum number if VCS_INFO_message_*_
1204 #                         variables vcs_info() will export.
1205 #   enable              - Checked in the 'init' context. If set to false,
1206 #                         vcs_info() will do nothing.
1207 #   disable             - Provide a list of systems, you don't want
1208 #                         the vcs_info() to check for repositories
1209 #                         (checked in the 'init' context, too).
1210 #   use-simple          - If there are two different ways of gathering
1211 #                         information, you can select the simpler one
1212 #                         by setting this style to true; the default
1213 #                         is to use the not-that-simple code, which is
1214 #                         potentially a lot slower but might be more
1215 #                         accurate in all possible cases.
1216 #   use-prompt-escapes  - determines if we assume that the assembled
1217 #                         string from vcs_info() includes prompt escapes.
1218 #                         (Used by vcs_info_lastmsg().
1219 #
1220 # The use-simple style is only available for the bzr backend.
1221 #
1222 # The default values for these in all contexts are:
1223 #   formats             " (%s)-[%b|%a]-"
1224 #   actionformats       " (%s)-[%b]-"
1225 #   branchformat        "%b:%r" (for bzr, svn and svk)
1226 #   nvcsformats         ""
1227 #   max-exports         2
1228 #   enable              true
1229 #   disable             (empty list)
1230 #   use-simple          false
1231 #   use-prompt-escapes  true
1232 #
1233 #
1234 # In normal formats and actionformats, the following replacements
1235 # are done:
1236 #   %s  - The vcs in use (git, hg, svn etc.)
1237 #   %b  - Information about the current branch.
1238 #   %a  - An identifier, that describes the action.
1239 #         Only makes sense in actionformats.
1240 #   %R  - base directory of the repository.
1241 #   %r  - repository name
1242 #         If %R is '/foo/bar/repoXY', %r is 'repoXY'.
1243 #   %S  - subdirectory within a repository. if $PWD is
1244 #         '/foo/bar/reposXY/beer/tasty', %S is 'beer/tasty'.
1245 #
1246 #
1247 # In branchformat these replacements are done:
1248 #   %b  - the branch name
1249 #   %r  - the current revision number
1250 #
1251 # Not all vcs backends have to support all replacements.
1252 # nvcsformat does not perform *any* replacements. It is just a string.
1253 #}}}
1254 #
1255 # ODDITIES:
1256 #{{{
1257 # If you want to use the %b (bold off) prompt expansion in 'formats', which
1258 # expands %b itself, use %%b. That will cause the vcs_info() expansion to
1259 # replace %%b with %b. So zsh's prompt expansion mechanism can handle it.
1260 # Similarly, to hand down %b from branchformat, use %%%%b. Sorry for this
1261 # inconvenience, but it cannot be easily avoided. Luckily we do not clash
1262 # with a lot of prompt expansions and this only needs to be done for those.
1263 # See 'man zshmisc' for details about EXPANSION OF PROMPT SEQUENCES.
1264 #}}}
1265 #
1266 # FUNCTION DESCRIPTIONS (public API):
1267 #{{{
1268 #   vcs_info()
1269 #       The main function, that runs all backends and assembles
1270 #       all data into ${VCS_INFO_message_*_}. This is the function
1271 #       you want to call from precmd() if you want to include
1272 #       up-to-date information in your prompt (see VARIABLE
1273 #       DESCRIPTION below).
1274 #
1275 #   vcs_info_printsys()
1276 #       Prints a list of all supported version control systems.
1277 #       Useful to find out possible contexts (and which of them are enabled)
1278 #       or values for the 'disable' style.
1279 #
1280 #   vcs_info_lastmsg()
1281 #       Outputs the last ${VCS_INFO_message_*_} value. Takes into account
1282 #       the value of the use-prompt-escapes style in ':vcs_info:formats'.
1283 #       It also only prints max-exports values.
1284 #
1285 # All functions named VCS_INFO_* are for internal use only.
1286 #}}}
1287 #
1288 # VARIABLE DESCRIPTION:
1289 #{{{
1290 #   ${VCS_INFO_message_N_}    (Note the trailing underscore)
1291 #       Where 'N' is an integer, eg: VCS_INFO_message_0_
1292 #       These variables are the storage for the informational message the
1293 #       last vcs_info() call has assembled. These are strongly connected
1294 #       to the formats, actionformats and nvcsformats styles described
1295 #       above. Those styles are lists. the first member of that list gets
1296 #       expanded into ${VCS_INFO_message_0_}, the second into
1297 #       ${VCS_INFO_message_1_} and the Nth into ${VCS_INFO_message_N-1_}.
1298 #       These parameters are exported into the environment.
1299 #       (See the max-exports style above.)
1300 #}}}
1301 #
1302 # EXAMPLES:
1303 #{{{
1304 #   Don't use vcs_info at all (even though it's in your prompt):
1305 #   % zstyle ':vcs_info:*' enable false
1306 #
1307 #   Disable the backends for bzr and svk:
1308 #   % zstyle ':vcs_info:*' disable bzr svk
1309 #
1310 #   Provide a special formats for git:
1311 #   % zstyle ':vcs_info:git:*' formats       ' GIT, BABY! [%b]'
1312 #   % zstyle ':vcs_info:git:*' actionformats ' GIT ACTION! [%b|%a]'
1313 #
1314 #   Use the quicker bzr backend (if you do, please report if it does
1315 #   the-right-thing[tm] - thanks):
1316 #   % zstyle ':vcs_info:bzr:*' use-simple true
1317 #
1318 #   Display the revision number in yellow for bzr and svn:
1319 #   % zstyle ':vcs_info:(svn|bzr):*' branchformat '%b%{'${fg[yellow]}'%}:%r'
1320 #
1321 # If you want colors, make sure you enclose the color codes in %{...%},
1322 # if you want to use the string provided by vcs_info() in prompts.
1323 #
1324 # Here is how to print the vcs infomation as a command:
1325 #   % alias vcsi='vcs_info command; vcs_info_lastmsg'
1326 #
1327 #   This way, you can even define different formats for output via
1328 #   vcs_info_lastmsg() in the ':vcs_info:command:*' namespace.
1329 #}}}
1330 #}}}
1331 # utilities
1332 VCS_INFO_adjust () { #{{{
1333     [[ -n ${vcs_comm[overwrite_name]} ]] && vcs=${vcs_comm[overwrite_name]}
1334     return 0
1335 }
1336 # }}}
1337 VCS_INFO_check_com () { #{{{
1338     (( ${+commands[$1]} )) && [[ -x ${commands[$1]} ]] && return 0
1339     return 1
1340 }
1341 # }}}
1342 VCS_INFO_formats () { # {{{
1343     setopt localoptions noksharrays
1344     local action=$1 branch=$2 base=$3
1345     local msg
1346     local -i i
1347
1348     if [[ -n ${action} ]] ; then
1349         zstyle -a ":vcs_info:${vcs}:${usercontext}" actionformats msgs
1350         (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b|%a]-'
1351     else
1352         zstyle -a ":vcs_info:${vcs}:${usercontext}" formats msgs
1353         (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b]-'
1354     fi
1355
1356     (( ${#msgs} > maxexports )) && msgs[${maxexports},-1]=()
1357     for i in {1..${#msgs}} ; do
1358         zformat -f msg ${msgs[$i]} a:${action} b:${branch} s:${vcs} r:${base:t} R:${base} S:"$(VCS_INFO_reposub ${base})"
1359         msgs[$i]=${msg}
1360     done
1361     return 0
1362 }
1363 # }}}
1364 VCS_INFO_maxexports () { #{{{
1365     local -ix maxexports
1366
1367     zstyle -s ":vcs_info:${vcs}:${usercontext}" "max-exports" maxexports || maxexports=2
1368     if [[ ${maxexports} != <-> ]] || (( maxexports < 1 )); then
1369         printf 'vcs_info(): expecting numeric arg >= 1 for max-exports (got %s).\n' ${maxexports}
1370         printf 'Defaulting to 2.\n'
1371         maxexports=2
1372     fi
1373 }
1374 # }}}
1375 VCS_INFO_nvcsformats () { #{{{
1376     setopt localoptions noksharrays
1377     local c v
1378
1379     if [[ $1 == 'preinit' ]] ; then
1380         c=default
1381         v=preinit
1382     fi
1383     zstyle -a ":vcs_info:${v:-$vcs}:${c:-$usercontext}" nvcsformats msgs
1384     (( ${#msgs} > maxexports )) && msgs[${maxexports},-1]=()
1385 }
1386 # }}}
1387 VCS_INFO_realpath () { #{{{
1388     # a portable 'readlink -f'
1389     # forcing a subshell, to ensure chpwd() is not removed
1390     # from the calling shell (if VCS_INFO_realpath() is called
1391     # manually).
1392     (
1393         (( ${+functions[chpwd]} )) && unfunction chpwd
1394         setopt chaselinks
1395         cd $1 2>/dev/null && pwd
1396     )
1397 }
1398 # }}}
1399 VCS_INFO_reposub () { #{{{
1400     setopt localoptions extendedglob
1401     local base=${1%%/##}
1402
1403     [[ ${PWD} == ${base}/* ]] || {
1404         printf '.'
1405         return 1
1406     }
1407     printf '%s' ${PWD#$base/}
1408     return 0
1409 }
1410 # }}}
1411 VCS_INFO_set () { #{{{
1412     setopt localoptions noksharrays
1413     local -i i j
1414
1415     if [[ $1 == '--clear' ]] ; then
1416         for i in {0..9} ; do
1417             unset VCS_INFO_message_${i}_
1418         done
1419     fi
1420     if [[ $1 == '--nvcs' ]] ; then
1421         [[ $2 == 'preinit' ]] && (( maxexports == 0 )) && (( maxexports = 1 ))
1422         for i in {0..$((maxexports - 1))} ; do
1423             typeset -gx VCS_INFO_message_${i}_=
1424         done
1425         VCS_INFO_nvcsformats $2
1426     fi
1427
1428     (( ${#msgs} - 1 < 0 )) && return 0
1429     for i in {0..$(( ${#msgs} - 1 ))} ; do
1430         (( j = i + 1 ))
1431         typeset -gx VCS_INFO_message_${i}_=${msgs[$j]}
1432     done
1433     return 0
1434 }
1435 # }}}
1436 # information gathering
1437 VCS_INFO_bzr_get_data () { # {{{
1438     setopt localoptions noksharrays
1439     local bzrbase bzrbr
1440     local -a bzrinfo
1441
1442     if zstyle -t ":vcs_info:${vcs}:${usercontext}" "use-simple" ; then
1443         bzrbase=${vcs_comm[basedir]}
1444         bzrinfo[2]=${bzrbase:t}
1445         if [[ -f ${bzrbase}/.bzr/branch/last-revision ]] ; then
1446             bzrinfo[1]=$(< ${bzrbase}/.bzr/branch/last-revision)
1447             bzrinfo[1]=${${bzrinfo[1]}%% *}
1448         fi
1449     else
1450         bzrbase=${${(M)${(f)"$( bzr info )"}:# ##branch\ root:*}/*: ##/}
1451         bzrinfo=( ${${${(M)${(f)"$( bzr version-info )"}:#(#s)(revno|branch-nick)*}/*: /}/*\//} )
1452         bzrbase="$(VCS_INFO_realpath ${bzrbase})"
1453     fi
1454
1455     zstyle -s ":vcs_info:${vcs}:${usercontext}" branchformat bzrbr || bzrbr="%b:%r"
1456     zformat -f bzrbr "${bzrbr}" "b:${bzrinfo[2]}" "r:${bzrinfo[1]}"
1457     VCS_INFO_formats '' "${bzrbr}" "${bzrbase}"
1458     return 0
1459 }
1460 # }}}
1461 VCS_INFO_cdv_get_data () { # {{{
1462     local cdvbase
1463
1464     cdvbase=${vcs_comm[basedir]}
1465     VCS_INFO_formats '' "${cdvbase:t}" "${cdvbase}"
1466     return 0
1467 }
1468 # }}}
1469 VCS_INFO_cvs_get_data () { # {{{
1470     local cvsbranch cvsbase basename
1471
1472     cvsbase="."
1473     while [[ -d "${cvsbase}/../CVS" ]]; do
1474         cvsbase="${cvsbase}/.."
1475     done
1476     cvsbase="$(VCS_INFO_realpath ${cvsbase})"
1477     cvsbranch=$(< ./CVS/Repository)
1478     basename=${cvsbase:t}
1479     cvsbranch=${cvsbranch##${basename}/}
1480     [[ -z ${cvsbranch} ]] && cvsbranch=${basename}
1481     VCS_INFO_formats '' "${cvsbranch}" "${cvsbase}"
1482     return 0
1483 }
1484 # }}}
1485 VCS_INFO_darcs_get_data () { # {{{
1486     local darcsbase
1487
1488     darcsbase=${vcs_comm[basedir]}
1489     VCS_INFO_formats '' "${darcsbase:t}" "${darcsbase}"
1490     return 0
1491 }
1492 # }}}
1493 VCS_INFO_git_getaction () { #{{{
1494     local gitaction='' gitdir=$1
1495     local tmp
1496
1497     for tmp in "${gitdir}/rebase-apply" \
1498                "${gitdir}/rebase"       \
1499                "${gitdir}/../.dotest" ; do
1500         if [[ -d ${tmp} ]] ; then
1501             if   [[ -f "${tmp}/rebasing" ]] ; then
1502                 gitaction="rebase"
1503             elif [[ -f "${tmp}/applying" ]] ; then
1504                 gitaction="am"
1505             else
1506                 gitaction="am/rebase"
1507             fi
1508             printf '%s' ${gitaction}
1509             return 0
1510         fi
1511     done
1512
1513     for tmp in "${gitdir}/rebase-merge/interactive" \
1514                "${gitdir}/.dotest-merge/interactive" ; do
1515         if [[ -f "${tmp}" ]] ; then
1516             printf '%s' "rebase-i"
1517             return 0
1518         fi
1519     done
1520
1521     for tmp in "${gitdir}/rebase-merge" \
1522                "${gitdir}/.dotest-merge" ; do
1523         if [[ -d "${tmp}" ]] ; then
1524             printf '%s' "rebase-m"
1525             return 0
1526         fi
1527     done
1528
1529     if [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
1530         printf '%s' "merge"
1531         return 0
1532     fi
1533
1534     if [[ -f "${gitdir}/BISECT_LOG" ]] ; then
1535         printf '%s' "bisect"
1536         return 0
1537     fi
1538     return 1
1539 }
1540 # }}}
1541 VCS_INFO_git_getbranch () { #{{{
1542     local gitbranch gitdir=$1
1543     local gitsymref='git symbolic-ref HEAD'
1544
1545     if    [[ -d "${gitdir}/rebase-apply" ]] \
1546        || [[ -d "${gitdir}/rebase" ]]       \
1547        || [[ -d "${gitdir}/../.dotest" ]]   \
1548        || [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
1549         gitbranch="$(${(z)gitsymref} 2> /dev/null)"
1550         [[ -z ${gitbranch} ]] && [[ -r ${gitdir}/rebase-apply/head-name ]] \
1551             && gitbranch="$(< ${gitdir}/rebase-apply/head-name)"
1552
1553     elif   [[ -f "${gitdir}/rebase-merge/interactive" ]] \
1554         || [[ -d "${gitdir}/rebase-merge" ]] ; then
1555         gitbranch="$(< ${gitdir}/rebase-merge/head-name)"
1556
1557     elif   [[ -f "${gitdir}/.dotest-merge/interactive" ]] \
1558         || [[ -d "${gitdir}/.dotest-merge" ]] ; then
1559         gitbranch="$(< ${gitdir}/.dotest-merge/head-name)"
1560
1561     else
1562         gitbranch="$(${(z)gitsymref} 2> /dev/null)"
1563
1564         if [[ $? -ne 0 ]] ; then
1565             gitbranch="$(git describe --exact-match HEAD 2>/dev/null)"
1566
1567             if [[ $? -ne 0 ]] ; then
1568                 gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
1569             fi
1570         fi
1571     fi
1572
1573     printf '%s' "${gitbranch##refs/heads/}"
1574     return 0
1575 }
1576 # }}}
1577 VCS_INFO_git_get_data () { # {{{
1578     setopt localoptions extendedglob
1579     local gitdir gitbase gitbranch gitaction
1580
1581     gitdir=${vcs_comm[gitdir]}
1582     gitbranch="$(VCS_INFO_git_getbranch ${gitdir})"
1583
1584     if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then
1585         return 1
1586     fi
1587
1588     VCS_INFO_adjust
1589     gitaction="$(VCS_INFO_git_getaction ${gitdir})"
1590     gitbase=${PWD%/${$( git rev-parse --show-prefix )%/##}}
1591     VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}"
1592     return 0
1593 }
1594 # }}}
1595 VCS_INFO_hg_get_data () { # {{{
1596     local hgbranch hgbase
1597
1598     hgbase=${vcs_comm[basedir]}
1599     hgbranch=$(< ${hgbase}/.hg/branch)
1600     VCS_INFO_formats '' "${hgbranch}" "${hgbase}"
1601     return 0
1602 }
1603 # }}}
1604 VCS_INFO_mtn_get_data () { # {{{
1605     local mtnbranch mtnbase
1606
1607     mtnbase=${vcs_comm[basedir]}
1608     mtnbranch=${${(M)${(f)"$( mtn status )"}:#(#s)Current branch:*}/*: /}
1609     VCS_INFO_formats '' "${mtnbranch}" "${mtnbase}"
1610     return 0
1611 }
1612 # }}}
1613 VCS_INFO_svk_get_data () { # {{{
1614     local svkbranch svkbase
1615
1616     svkbase=${vcs_comm[basedir]}
1617     zstyle -s ":vcs_info:${vcs}:${usercontext}" branchformat svkbranch || svkbranch="%b:%r"
1618     zformat -f svkbranch "${svkbranch}" "b:${vcs_comm[branch]}" "r:${vcs_comm[revision]}"
1619     VCS_INFO_formats '' "${svkbranch}" "${svkbase}"
1620     return 0
1621 }
1622 # }}}
1623 VCS_INFO_svn_get_data () { # {{{
1624     setopt localoptions noksharrays
1625     local svnbase svnbranch
1626     local -a svninfo
1627
1628     svnbase="."
1629     while [[ -d "${svnbase}/../.svn" ]]; do
1630         svnbase="${svnbase}/.."
1631     done
1632     svnbase="$(VCS_INFO_realpath ${svnbase})"
1633     svninfo=( ${${${(M)${(f)"$( svn info )"}:#(#s)(URL|Revision)*}/*: /}/*\//} )
1634
1635     zstyle -s ":vcs_info:${vcs}:${usercontext}" branchformat svnbranch || svnbranch="%b:%r"
1636     zformat -f svnbranch "${svnbranch}" "b:${svninfo[1]}" "r:${svninfo[2]}"
1637     VCS_INFO_formats '' "${svnbranch}" "${svnbase}"
1638     return 0
1639 }
1640 # }}}
1641 VCS_INFO_tla_get_data () { # {{{
1642     local tlabase tlabranch
1643
1644     tlabase="$(VCS_INFO_realpath ${vcs_comm[basedir]})"
1645     # tree-id gives us something like 'foo@example.com/demo--1.0--patch-4', so:
1646     tlabranch=${${"$( tla tree-id )"}/*\//}
1647     VCS_INFO_formats '' "${tlabranch}" "${tlabase}"
1648     return 0
1649 }
1650 # }}}
1651 # detection
1652 VCS_INFO_detect_by_dir() { #{{{
1653     local dirname=$1
1654     local basedir="." realbasedir
1655
1656     realbasedir="$(VCS_INFO_realpath ${basedir})"
1657     while [[ ${realbasedir} != '/' ]]; do
1658         if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
1659             [[ -d ${basedir}/${dirname} ]] && \
1660             [[ -f ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
1661                 break
1662         else
1663             [[ -d ${basedir}/${dirname} ]] && break
1664         fi
1665
1666         basedir=${basedir}/..
1667         realbasedir="$(VCS_INFO_realpath ${basedir})"
1668     done
1669
1670     [[ ${realbasedir} == "/" ]] && return 1
1671     vcs_comm[basedir]=${realbasedir}
1672     return 0
1673 }
1674 # }}}
1675 VCS_INFO_bzr_detect() { #{{{
1676     VCS_INFO_check_com bzr || return 1
1677     vcs_comm[detect_need_file]=branch/format
1678     VCS_INFO_detect_by_dir '.bzr'
1679     return $?
1680 }
1681 # }}}
1682 VCS_INFO_cdv_detect() { #{{{
1683     VCS_INFO_check_com cdv || return 1
1684     vcs_comm[detect_need_file]=format
1685     VCS_INFO_detect_by_dir '.cdv'
1686     return $?
1687 }
1688 # }}}
1689 VCS_INFO_cvs_detect() { #{{{
1690     VCS_INFO_check_com svn || return 1
1691     [[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0
1692     return 1
1693 }
1694 # }}}
1695 VCS_INFO_darcs_detect() { #{{{
1696     VCS_INFO_check_com darcs || return 1
1697     vcs_comm[detect_need_file]=format
1698     VCS_INFO_detect_by_dir '_darcs'
1699     return $?
1700 }
1701 # }}}
1702 VCS_INFO_git_detect() { #{{{
1703     if VCS_INFO_check_com git && git rev-parse --is-inside-work-tree &> /dev/null ; then
1704         vcs_comm[gitdir]="$(git rev-parse --git-dir 2> /dev/null)" || return 1
1705         if   [[ -d ${vcs_comm[gitdir]}/svn ]]             ; then vcs_comm[overwrite_name]='git-svn'
1706         elif [[ -d ${vcs_comm[gitdir]}/refs/remotes/p4 ]] ; then vcs_comm[overwrite_name]='git-p4' ; fi
1707         return 0
1708     fi
1709     return 1
1710 }
1711 # }}}
1712 VCS_INFO_hg_detect() { #{{{
1713     VCS_INFO_check_com hg || return 1
1714     vcs_comm[detect_need_file]=branch
1715     VCS_INFO_detect_by_dir '.hg'
1716     return $?
1717 }
1718 # }}}
1719 VCS_INFO_mtn_detect() { #{{{
1720     VCS_INFO_check_com mtn || return 1
1721     vcs_comm[detect_need_file]=revision
1722     VCS_INFO_detect_by_dir '_MTN'
1723     return $?
1724 }
1725 # }}}
1726 VCS_INFO_svk_detect() { #{{{
1727     setopt localoptions noksharrays extendedglob
1728     local -a info
1729     local -i fhash
1730     fhash=0
1731
1732     VCS_INFO_check_com svk || return 1
1733     [[ -f ~/.svk/config ]] || return 1
1734
1735     # This detection function is a bit different from the others.
1736     # We need to read svk's config file to detect a svk repository
1737     # in the first place. Therefore, we'll just proceed and read
1738     # the other information, too. This is more then any of the
1739     # other detections do but this takes only one file open for
1740     # svk at most. VCS_INFO_svk_get_data() get simpler, too. :-)
1741     while IFS= read -r line ; do
1742         if [[ -n ${vcs_comm[basedir]} ]] ; then
1743             line=${line## ##}
1744             [[ ${line} == depotpath:* ]] && vcs_comm[branch]=${line##*/}
1745             [[ ${line} == revision:* ]] && vcs_comm[revision]=${line##*[[:space:]]##}
1746             [[ -n ${vcs_comm[branch]} ]] && [[ -n ${vcs_comm[revision]} ]] && break
1747             continue
1748         fi
1749         (( fhash > 0 )) && [[ ${line} == '  '[^[:space:]]*:* ]] && break
1750         [[ ${line} == '  hash:'* ]] && fhash=1 && continue
1751         (( fhash == 0 )) && continue
1752         [[ ${PWD}/ == ${${line## ##}%:*}/* ]] && vcs_comm[basedir]=${${line## ##}%:*}
1753     done < ~/.svk/config
1754
1755     [[ -n ${vcs_comm[basedir]} ]]  && \
1756     [[ -n ${vcs_comm[branch]} ]]   && \
1757     [[ -n ${vcs_comm[revision]} ]] && return 0
1758     return 1
1759 }
1760 # }}}
1761 VCS_INFO_svn_detect() { #{{{
1762     VCS_INFO_check_com svn || return 1
1763     [[ -d ".svn" ]] && return 0
1764     return 1
1765 }
1766 # }}}
1767 VCS_INFO_tla_detect() { #{{{
1768     VCS_INFO_check_com tla || return 1
1769     vcs_comm[basedir]="$(tla tree-root 2> /dev/null)" && return 0
1770     return 1
1771 }
1772 # }}}
1773 # public API
1774 vcs_info_printsys () { # {{{
1775     vcs_info print_systems_
1776 }
1777 # }}}
1778 vcs_info_lastmsg () { # {{{
1779     local -i i
1780
1781     VCS_INFO_maxexports
1782     for i in {0..$((maxexports - 1))} ; do
1783         printf '$VCS_INFO_message_%d_: "' $i
1784         if zstyle -T ':vcs_info:formats:command' use-prompt-escapes ; then
1785             print -nP ${(P)${:-VCS_INFO_message_${i}_}}
1786         else
1787             print -n ${(P)${:-VCS_INFO_message_${i}_}}
1788         fi
1789         printf '"\n'
1790     done
1791 }
1792 # }}}
1793 vcs_info () { # {{{
1794     local -i found
1795     local -a VCSs disabled
1796     local -x vcs usercontext
1797     local -ax msgs
1798     local -Ax vcs_comm
1799
1800     vcs="init"
1801     VCSs=(git hg bzr darcs svk mtn svn cvs cdv tla)
1802     case $1 in
1803         (print_systems_)
1804             zstyle -a ":vcs_info:${vcs}:${usercontext}" "disable" disabled
1805             print -l '# list of supported version control backends:' \
1806                      '# disabled systems are prefixed by a hash sign (#)'
1807             for vcs in ${VCSs} ; do
1808                 [[ -n ${(M)disabled:#${vcs}} ]] && printf '#'
1809                 printf '%s\n' ${vcs}
1810             done
1811             print -l '# flavours (cannot be used in the disable style; they' \
1812                      '# are disabled with their master [git-svn -> git]):'   \
1813                      git-{p4,svn}
1814             return 0
1815             ;;
1816         ('')
1817             [[ -z ${usercontext} ]] && usercontext=default
1818             ;;
1819         (*) [[ -z ${usercontext} ]] && usercontext=$1
1820             ;;
1821     esac
1822
1823     zstyle -T ":vcs_info:${vcs}:${usercontext}" "enable" || {
1824         [[ -n ${VCS_INFO_message_0_} ]] && VCS_INFO_set --clear
1825         return 0
1826     }
1827     zstyle -a ":vcs_info:${vcs}:${usercontext}" "disable" disabled
1828     VCS_INFO_maxexports
1829
1830     (( found = 0 ))
1831     for vcs in ${VCSs} ; do
1832         [[ -n ${(M)disabled:#${vcs}} ]] && continue
1833         vcs_comm=()
1834         VCS_INFO_${vcs}_detect && (( found = 1 )) && break
1835     done
1836
1837     (( found == 0 )) && {
1838         VCS_INFO_set --nvcs
1839         return 0
1840     }
1841
1842     VCS_INFO_${vcs}_get_data || {
1843         VCS_INFO_set --nvcs
1844         return 1
1845     }
1846
1847     VCS_INFO_set
1848     return 0
1849 }
1850
1851 VCS_INFO_set --nvcs preinit
1852 # }}}
1853
1854 # change vcs_info formats for the grml prompt
1855 if [[ "$TERM" == dumb ]] ; then
1856     zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] "
1857     zstyle ':vcs_info:*' formats       "(%s%)-[%b] "
1858 else
1859     # these are the same, just with a lot of colours:
1860     zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOUR} "
1861     zstyle ':vcs_info:*' formats       "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOUR}%} "
1862     zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YELLOW}%r"
1863 fi
1864
1865 # }}}
1866
1867 # {{{ set prompt
1868 if zrcautoload promptinit && promptinit 2>/dev/null ; then
1869     promptinit # people should be able to use their favourite prompt
1870 else
1871     print 'Notice: no promptinit available :('
1872 fi
1873
1874 setopt prompt_subst
1875
1876 # make sure to use right prompt only when not running a command
1877 is41 && setopt transient_rprompt
1878
1879 is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
1880     [[ $NOPRECMD -gt 0 ]] && return 0
1881     # update VCS information
1882     vcs_info
1883
1884     # allow manual overwriting of RPROMPT
1885     if [[ -n $RPROMPT ]] ; then
1886         [[ $TERM == screen* ]] && print -nP "\ekzsh\e\\"
1887         # return 0
1888     fi
1889     # just use DONTSETRPROMPT=1 to be able to overwrite RPROMPT
1890     if [[ $DONTSETRPROMPT -eq 0 ]] ; then
1891         if [[ $BATTERY -gt 0 ]] ; then
1892             # update BATTERY information
1893             battery
1894             RPROMPT="%(?..:()% ${PERCENT}${SCREENTITLE}"
1895             # RPROMPT="${PERCENT}${SCREENTITLE}"
1896         else
1897             RPROMPT="%(?..:()% ${SCREENTITLE}"
1898             # RPROMPT="${SCREENTITLE}"
1899         fi
1900     fi
1901     # adjust title of xterm
1902     # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
1903     case $TERM in
1904         (xterm*|rxvt)
1905             print -Pn "\e]0;%n@%m: %~\a"
1906             ;;
1907     esac
1908 }
1909
1910 # preexec() => a function running before every command
1911 is4 && [[ $NOPRECMD -eq 0 ]] && \
1912 preexec () {
1913     [[ $NOPRECMD -gt 0 ]] && return 0
1914 # set hostname if not running on host with name 'grml'
1915     if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != $(hostname) ]] ; then
1916        NAME="@$HOSTNAME"
1917     fi
1918 # get the name of the program currently running and hostname of local machine
1919 # set screen window title if running in a screen
1920     if [[ "$TERM" == screen* ]] ; then
1921         # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}       # don't use hostname
1922         local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
1923         echo -ne "\ek$CMD\e\\"
1924     fi
1925 # set the screen title to "zsh" when sitting at the command prompt:
1926     if [[ "$TERM" == screen* ]] ; then
1927         SCREENTITLE=$'%{\ekzsh\e\\%}'
1928     else
1929         SCREENTITLE=''
1930     fi
1931 # adjust title of xterm
1932     case $TERM in
1933         (xterm*|rxvt)
1934             print -Pn "\e]0;%n@%m: $1\a"
1935             ;;
1936     esac
1937 }
1938
1939 EXITCODE="%(?..%?%1v )"
1940 PS2='\`%_> '      # secondary prompt, printed when the shell needs more information to complete a command.
1941 PS3='?# '         # selection prompt used within a select loop.
1942 PS4='+%N:%i:%_> ' # the execution trace prompt (setopt xtrace). default: '+%N:%i>'
1943
1944 # set variable debian_chroot if running in a chroot with /etc/debian_chroot
1945 if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
1946     debian_chroot=$(cat /etc/debian_chroot)
1947 fi
1948
1949 # don't use colors on dumb terminals (like emacs):
1950 if [[ "$TERM" == dumb ]] ; then
1951     PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
1952 else
1953     # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended prompt
1954     # set variable identifying the chroot you work in (used in the prompt below)
1955     if [[ $GRMLPROMPT -gt 0 ]] ; then
1956         PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
1957 ${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# "
1958     else
1959         # This assembles the primary prompt string
1960         if (( EUID != 0 )); then
1961             PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
1962         else
1963             PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
1964         fi
1965     fi
1966 fi
1967
1968 # if we are inside a grml-chroot set a specific prompt theme
1969 if [[ -n "$GRML_CHROOT" ]] ; then
1970     PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "
1971 fi
1972 # }}}
1973
1974 # {{{ 'hash' some often used directories
1975 #d# start
1976 hash -d deb=/var/cache/apt/archives
1977 hash -d doc=/usr/share/doc
1978 hash -d linux=/lib/modules/$(command uname -r)/build/
1979 hash -d log=/var/log
1980 hash -d slog=/var/log/syslog
1981 hash -d src=/usr/src
1982 hash -d templ=/usr/share/doc/grml-templates
1983 hash -d tt=/usr/share/doc/texttools-doc
1984 hash -d www=/var/www
1985 #d# end
1986 # }}}
1987
1988 # {{{ some aliases
1989 if [[ $UID -eq 0 ]] ; then
1990     [[ -r /etc/grml/screenrc ]] && alias screen='/usr/bin/screen -c /etc/grml/screenrc'
1991 elif [[ -r $HOME/.screenrc ]] ; then
1992     alias screen="/usr/bin/screen -c $HOME/.screenrc"
1993 else
1994     [[ -r /etc/grml/screenrc_grml ]] && alias screen='/usr/bin/screen -c /etc/grml/screenrc_grml'
1995 fi
1996
1997 # do we have GNU ls with color-support?
1998 if ls --help 2>/dev/null | grep -- --color= >/dev/null && [[ "$TERM" != dumb ]] ; then
1999     #a1# execute \kbd{@a@}:\quad ls with colors
2000     alias ls='ls -b -CF --color=auto'
2001     #a1# execute \kbd{@a@}:\quad list all files, with colors
2002     alias la='ls -la --color=auto'
2003     #a1# long colored list, without dotfiles (@a@)
2004     alias ll='ls -l --color=auto'
2005     #a1# long colored list, human readable sizes (@a@)
2006     alias lh='ls -hAl --color=auto'
2007     #a1# List files, append qualifier to filenames \\&\quad(\kbd{/} for directories, \kbd{@} for symlinks ...)
2008     alias l='ls -lF --color=auto'
2009 else
2010     alias ls='ls -b -CF'
2011     alias la='ls -la'
2012     alias ll='ls -l'
2013     alias lh='ls -hAl'
2014     alias l='ls -lF'
2015 fi
2016
2017 alias mdstat='cat /proc/mdstat'
2018 alias ...='cd ../../'
2019
2020 # generate alias named "$KERNELVERSION-reboot" so you can use boot with kexec:
2021 if [[ -x /sbin/kexec ]] && [[ -r /proc/cmdline ]] ; then
2022     alias "$(uname -r)-reboot"="kexec -l --initrd=/boot/initrd.img-"$(uname -r)" --command-line=\"$(cat /proc/cmdline)\" /boot/vmlinuz-"$(uname -r)""
2023 fi
2024
2025 alias cp='nocorrect cp'         # no spelling correction on cp
2026 alias mkdir='nocorrect mkdir'   # no spelling correction on mkdir
2027 alias mv='nocorrect mv'         # no spelling correction on mv
2028 alias rm='nocorrect rm'         # no spelling correction on rm
2029
2030 #a1# Execute \kbd{rmdir}
2031 alias rd='rmdir'
2032 #a1# Execute \kbd{rmdir}
2033 alias md='mkdir'
2034
2035 # see http://www.cl.cam.ac.uk/~mgk25/unicode.html#term for details
2036 alias term2iso="echo 'Setting terminal to iso mode' ; print -n '\e%@'"
2037 alias term2utf="echo 'Setting terminal to utf-8 mode'; print -n '\e%G'"
2038
2039 # make sure it is not assigned yet
2040 [[ $(whence -w utf2iso &>/dev/null) == 'utf2iso: alias' ]] && unalias utf2iso
2041
2042 utf2iso() {
2043     if isutfenv ; then
2044         for ENV in $(env | command grep -i '.utf') ; do
2045             eval export "$(echo $ENV | sed 's/UTF-8/iso885915/ ; s/utf8/iso885915/')"
2046         done
2047     fi
2048 }
2049
2050 # make sure it is not assigned yet
2051 [[ $(whence -w iso2utf &>/dev/null) == 'iso2utf: alias' ]] && unalias iso2utf
2052 iso2utf() {
2053     if ! isutfenv ; then
2054         for ENV in $(env | command grep -i '\.iso') ; do
2055             eval export "$(echo $ENV | sed 's/iso.*/UTF-8/ ; s/ISO.*/UTF-8/')"
2056         done
2057     fi
2058 }
2059
2060 # set up software synthesizer via speakup
2061 swspeak() {
2062     if [ -x /usr/sbin/swspeak-setup ] ; then
2063        setopt singlelinezle
2064        unsetopt prompt_cr
2065        export PS1="%m%# "
2066        /usr/sbin/swspeak-setup $@
2067      else # old version:
2068         aumix -w 90 -v 90 -p 90 -m 90
2069         if ! [[ -r /dev/softsynth ]] ; then
2070             flite -o play -t "Sorry, software synthesizer not available. Did you boot with swspeak bootoption?"
2071             return 1
2072         else
2073            setopt singlelinezle
2074            unsetopt prompt_cr
2075            export PS1="%m%# "
2076             nice -n -20 speechd-up
2077             sleep 2
2078             flite -o play -t "Finished setting up software synthesizer"
2079         fi
2080      fi
2081 }
2082
2083 # I like clean prompt, so provide simple way to get that
2084 check_com 0 || alias 0='return 0'
2085
2086 # for really lazy people like mika:
2087 check_com S &>/dev/null || alias S='screen'
2088 check_com s &>/dev/null || alias s='ssh'
2089
2090 # get top 10 shell commands:
2091 alias top10='print -l ? ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
2092
2093 # truecrypt; use e.g. via 'truec /dev/ice /mnt/ice' or 'truec -i'
2094 if check_com -c truecrypt ; then
2095     if isutfenv ; then
2096         alias truec='truecrypt --mount-options "rw,sync,dirsync,users,uid=1000,gid=users,umask=077,utf8" '
2097     else
2098         alias truec='truecrypt --mount-options "rw,sync,dirsync,users,uid=1000,gid=users,umask=077" '
2099     fi
2100 fi
2101
2102 #f1# Hints for the use of zsh on grml
2103 zsh-help() {
2104     print "$bg[white]$fg[black]
2105 zsh-help - hints for use of zsh on grml
2106 =======================================$reset_color"
2107
2108     print '
2109 Main configuration of zsh happens in /etc/zsh/zshrc (global)
2110 and /etc/skel/.zshrc which is copied to $HOME/.zshrc once.
2111 The files are part of the package grml-etc-core, if you want to
2112 use them on a non-grml-system just get the tar.gz from
2113 http://deb.grml.org/ or get the files from the mercurial
2114 repository:
2115
2116   http://git.grml.org/?p=grml-etc-core.git;a=blob_plain;f=etc/zsh/zshrc
2117   http://git.grml.org/?p=grml-etc-core.git;a=blob_plain;f=etc/skel/.zshrc
2118
2119 If you want to stay in sync with zsh configuration of grml
2120 run '\''ln -sf /etc/skel/.zshrc $HOME/.zshrc'\'' and configure
2121 your own stuff in $HOME/.zshrc.local. System wide configuration
2122 without touching configuration files of grml can take place
2123 in /etc/zsh/zshrc.local.
2124
2125 If you want to use the configuration of user grml also when
2126 running as user root just run '\''zshskel'\'' which will source
2127 the file /etc/skel/.zshrc.
2128
2129 For information regarding zsh start at http://grml.org/zsh/
2130
2131 Take a look at grml'\''s zsh refcard:
2132 % xpdf =(zcat /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)
2133
2134 Check out the main zsh refcard:
2135 % '$BROWSER' http://www.bash2zsh.com/zsh_refcard/refcard.pdf
2136
2137 And of course visit the zsh-lovers:
2138 % man zsh-lovers
2139
2140 You can adjust some options through environment variables when
2141 invoking zsh without having to edit configuration files.
2142 Basically meant for bash users who are not used to the power of
2143 the zsh yet. :)
2144
2145   "NOCOR=1    zsh" => deactivate automatic correction
2146   "NOMENU=1   zsh" => do not use auto menu completion (note: use ctrl-d for completion instead!)
2147   "NOPRECMD=1 zsh" => disable the precmd + preexec commands (set GNU screen title)
2148   "BATTERY=1  zsh" => activate battery status (via acpi) on right side of prompt
2149
2150 A value greater than 0 is enables a feature; a value equal to zero
2151 disables it. If you like one or the other of these settings, you can
2152 add them to ~/.zshenv to ensure they are set when sourcing grml'\''s
2153 zshrc.'
2154
2155     print "
2156 $bg[white]$fg[black]
2157 Please report wishes + bugs to the grml-team: http://grml.org/bugs/
2158 Enjoy your grml system with the zsh!$reset_color"
2159 }
2160
2161 # debian stuff
2162 if [[ -r /etc/debian_version ]] ; then
2163     #a3# Execute \kbd{apt-cache search}
2164     alias acs='apt-cache search'
2165     #a3# Execute \kbd{apt-cache show}
2166     alias acsh='apt-cache show'
2167     #a3# Execute \kbd{apt-cache policy}
2168     alias acp='apt-cache policy'
2169     #a3# Execute \kbd{apt-get dist-upgrade}
2170     salias adg="apt-get dist-upgrade"
2171     #a3# Execute \kbd{apt-get install}
2172     salias agi="apt-get install"
2173     #a3# Execute \kbd{aptitude install}
2174     salias ati="aptitude install"
2175     #a3# Execute \kbd{apt-get upgrade}
2176     salias ag="apt-get upgrade"
2177     #a3# Execute \kbd{apt-get update}
2178     salias au="apt-get update"
2179     #a3# Execute \kbd{aptitude update ; aptitude safe-upgrade}
2180     salias -a up="aptitude update ; aptitude safe-upgrade"
2181     #a3# Execute \kbd{dpkg-buildpackage}
2182     alias dbp='dpkg-buildpackage'
2183     #a3# Execute \kbd{grep-excuses}
2184     alias ge='grep-excuses'
2185
2186     # debian upgrade
2187     #f3# Execute \kbd{apt-get update \&\& }\\&\quad \kbd{apt-get dist-upgrade}
2188     upgrade() {
2189         if [[ -z "$1" ]] ; then
2190             $SUDO apt-get update
2191             $SUDO apt-get -u upgrade
2192         else
2193             ssh $1 $SUDO apt-get update
2194             # ask before the upgrade
2195             local dummy
2196             ssh $1 $SUDO apt-get --no-act upgrade
2197             echo -n 'Process the upgrade?'
2198             read -q dummy
2199             if [[ $dummy == "y" ]] ; then
2200                 ssh $1 $SUDO apt-get -u upgrade --yes
2201             fi
2202         fi
2203     }
2204
2205     # get a root shell as normal user in live-cd mode:
2206     if isgrmlcd && [[ $UID -ne 0 ]] ; then
2207        alias su="sudo su"
2208      fi
2209
2210     #a1# Take a look at the syslog: \kbd{\$PAGER /var/log/syslog}
2211     alias llog="$PAGER /var/log/syslog"     # take a look at the syslog
2212     #a1# Take a look at the syslog: \kbd{tail -f /var/log/syslog}
2213     alias tlog="tail -f /var/log/syslog"    # follow the syslog
2214     #a1# (Re)-source \kbd{/etc/skel/.zshrc}
2215     alias zshskel="source /etc/skel/.zshrc" # source skeleton zshrc
2216 fi
2217
2218 # sort installed Debian-packages by size
2219 if check_com -c grep-status ; then
2220     #a3# List installed Debian-packages sorted by size
2221     alias debs-by-size='grep-status -FStatus -sInstalled-Size,Package -n "install ok installed" | paste -sd "  \n" | sort -rn'
2222 fi
2223
2224 # if cdrecord is a symlink (to wodim) or isn't present at all warn:
2225 if [[ -L /usr/bin/cdrecord ]] || ! check_com -c cdrecord ; then
2226     if check_com -c wodim ; then
2227         alias cdrecord="echo 'cdrecord is not provided under its original name by Debian anymore.
2228 See #377109 in the BTS of Debian for more details.
2229
2230 Please use the wodim binary instead' ; return 1"
2231     fi
2232 fi
2233
2234 # get_tw_cli has been renamed into get_3ware
2235 if check_com -c get_3ware ; then
2236     get_tw_cli() {
2237         echo 'Warning: get_tw_cli has been renamed into get_3ware. Invoking get_3ware for you.'>&2
2238         get_3ware
2239     }
2240 fi
2241
2242 # I hate lacking backward compatibility, so provide an alternative therefore
2243 if ! check_com -c apache2-ssl-certificate ; then
2244
2245     apache2-ssl-certificate() {
2246
2247     print 'Debian does not ship apache2-ssl-certificate anymore (see #398520). :('
2248     print 'You might want to take a look at Debian the package ssl-cert as well.'
2249     print 'To generate a certificate for use with apache2 follow the instructions:'
2250
2251     echo '
2252
2253 export RANDFILE=/dev/random
2254 mkdir /etc/apache2/ssl/
2255 openssl req $@ -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.pem
2256 chmod 600 /etc/apache2/ssl/apache.pem
2257
2258 Run "grml-tips ssl-certificate" if you need further instructions.
2259 '
2260     }
2261 fi
2262 # }}}
2263
2264 # {{{ Use hard limits, except for a smaller stack and no core dumps
2265 unlimit
2266 is425 && limit stack 8192
2267 isgrmlcd && limit core 0 # important for a live-cd-system
2268 limit -s
2269 # }}}
2270
2271 # {{{ completion system
2272
2273 # called later (via is4 && grmlcomp)
2274 # notice: use 'zstyle' for getting current settings
2275 #         press ^Xh (control-x h) for getting tags in context; ^X? (control-x ?) to run complete_debug with trace output
2276 grmlcomp() {
2277     # TODO: This could use some additional information
2278
2279     # allow one error for every three characters typed in approximate completer
2280     zstyle ':completion:*:approximate:'    max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
2281
2282     # don't complete backup files as executables
2283     zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)'
2284
2285     # start menu completion only if it could find no unambiguous initial string
2286     zstyle ':completion:*:correct:*'       insert-unambiguous true
2287     zstyle ':completion:*:corrections'     format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
2288     zstyle ':completion:*:correct:*'       original true
2289
2290     # activate color-completion
2291     zstyle ':completion:*:default'         list-colors ${(s.:.)LS_COLORS}
2292
2293     # format on completion
2294     zstyle ':completion:*:descriptions'    format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
2295
2296     # complete 'cd -<tab>' with menu
2297     zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
2298
2299     # insert all expansions for expand completer
2300     zstyle ':completion:*:expand:*'        tag-order all-expansions
2301     zstyle ':completion:*:history-words'   list false
2302
2303     # activate menu
2304     zstyle ':completion:*:history-words'   menu yes
2305
2306     # ignore duplicate entries
2307     zstyle ':completion:*:history-words'   remove-all-dups yes
2308     zstyle ':completion:*:history-words'   stop yes
2309
2310     # match uppercase from lowercase
2311     zstyle ':completion:*'                 matcher-list 'm:{a-z}={A-Z}'
2312
2313     # separate matches into groups
2314     zstyle ':completion:*:matches'         group 'yes'
2315     zstyle ':completion:*'                 group-name ''
2316
2317     if [[ "$NOMENU" -eq 0 ]] ; then
2318         # if there are more than 5 options allow selecting from a menu
2319         zstyle ':completion:*'               menu select=5
2320     else
2321         # don't use any menus at all
2322         setopt no_auto_menu
2323     fi
2324
2325     zstyle ':completion:*:messages'        format '%d'
2326     zstyle ':completion:*:options'         auto-description '%d'
2327
2328     # describe options in full
2329     zstyle ':completion:*:options'         description 'yes'
2330
2331     # on processes completion complete all user processes
2332     zstyle ':completion:*:processes'       command 'ps -au$USER'
2333
2334     # offer indexes before parameters in subscripts
2335     zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
2336
2337     # provide verbose completion information
2338     zstyle ':completion:*'                 verbose true
2339
2340     # recent (as of Dec 2007) zsh versions are able to provide descriptions
2341     # for commands (read: 1st word in the line) that it will list for the user
2342     # to choose from. The following disables that, because it's not exactly fast.
2343     zstyle ':completion:*:-command-:*:'    verbose false
2344
2345     # set format for warnings
2346     zstyle ':completion:*:warnings'        format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
2347
2348     # define files to ignore for zcompile
2349     zstyle ':completion:*:*:zcompile:*'    ignored-patterns '(*~|*.zwc)'
2350     zstyle ':completion:correct:'          prompt 'correct to: %e'
2351
2352     # Ignore completion functions for commands you don't have:
2353     zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
2354
2355     # Provide more processes in completion of programs like killall:
2356     zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
2357
2358     # complete manual by their section
2359     zstyle ':completion:*:manuals'    separate-sections true
2360     zstyle ':completion:*:manuals.*'  insert-sections   true
2361     zstyle ':completion:*:man:*'      menu yes select
2362
2363     # run rehash on completion so new installed program are found automatically:
2364     _force_rehash() {
2365         (( CURRENT == 1 )) && rehash
2366         return 1
2367     }
2368
2369     ## correction
2370     # some people don't like the automatic correction - so run 'NOCOR=1 zsh' to deactivate it
2371     if [[ "$NOCOR" -gt 0 ]] ; then
2372         zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _files _ignored
2373         setopt nocorrect
2374     else
2375         # try to be smart about when to use what completer...
2376         setopt correct
2377         zstyle -e ':completion:*' completer '
2378             if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]] ; then
2379                 _last_try="$HISTNO$BUFFER$CURSOR"
2380                 reply=(_complete _match _ignored _prefix _files)
2381             else
2382                 if [[ $words[1] == (rm|mv) ]] ; then
2383                     reply=(_complete _files)
2384                 else
2385                     reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
2386                 fi
2387             fi'
2388     fi
2389
2390     # zstyle ':completion:*' completer _complete _correct _approximate
2391     # zstyle ':completion:*' expand prefix suffix
2392
2393     # complete shell aliases
2394     # zstyle ':completion:*' completer _expand_alias _complete _approximate
2395
2396     # command for process lists, the local web server details and host completion
2397     zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
2398
2399     # caching
2400     [[ -d $ZSHDIR/cache ]] && zstyle ':completion:*' use-cache yes && \
2401                             zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
2402
2403     # host completion /* add brackets as vim can't parse zsh's complex cmdlines 8-) {{{ */
2404     if is42 ; then
2405         [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
2406         [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
2407     else
2408         _ssh_hosts=()
2409         _etc_hosts=()
2410     fi
2411     hosts=(
2412         $(hostname)
2413         "$_ssh_hosts[@]"
2414         "$_etc_hosts[@]"
2415         grml.org
2416         localhost
2417     )
2418     zstyle ':completion:*:hosts' hosts $hosts
2419     #  zstyle '*' hosts $hosts
2420
2421     # specify your logins:
2422     # my_accounts=(
2423     #  {grml,grml1}@foo.invalid
2424     #  grml-devel@bar.invalid
2425     # )
2426     # other_accounts=(
2427     #  {fred,root}@foo.invalid
2428     #  vera@bar.invalid
2429     # )
2430     # zstyle ':completion:*:my-accounts' users-hosts $my_accounts
2431     # zstyle ':completion:*:other-accounts' users-hosts $other_accounts
2432
2433     # specify specific port/service settings:
2434     #  telnet_users_hosts_ports=(
2435     #    user1@host1:
2436     #    user2@host2:
2437     #    @mail-server:{smtp,pop3}
2438     #    @news-server:nntp
2439     #    @proxy-server:8000
2440     #  )
2441     # zstyle ':completion:*:*:telnet:*' users-hosts-ports $telnet_users_hosts_ports
2442
2443     # use generic completion system for programs not yet defined; (_gnu_generic works
2444     # with commands that provide a --help option with "standard" gnu-like output.)
2445     compdef _gnu_generic tail head feh cp mv df stow uname ipacsum fetchipac
2446
2447     # see upgrade function in this file
2448     compdef _hosts upgrade
2449 }
2450 # }}}
2451
2452 # {{{ grmlstuff
2453 grmlstuff() {
2454 # people should use 'grml-x'!
2455     startx() {
2456         if [[ -e /etc/X11/xorg.conf ]] ; then
2457             [[ -x /usr/bin/startx ]] && /usr/bin/startx "$@" || /usr/X11R6/bin/startx "$@"
2458         else
2459             echo "Please use the script \"grml-x\" for starting the X Window System
2460 because there does not exist /etc/X11/xorg.conf yet.
2461 If you want to use startx anyway please call \"/usr/bin/startx\"."
2462             return -1
2463         fi
2464     }
2465
2466     xinit() {
2467         if [[ -e /etc/X11/xorg.conf ]] ; then
2468             [[ -x /usr/bin/xinit ]] && /usr/bin/xinit || /usr/X11R6/bin/xinit
2469         else
2470             echo "Please use the script \"grml-x\" for starting the X Window System.
2471 because there does not exist /etc/X11/xorg.conf yet.
2472 If you want to use xinit anyway please call \"/usr/bin/xinit\"."
2473             return -1
2474         fi
2475     }
2476
2477     if check_com -c 915resolution ; then
2478         alias 855resolution='echo -e "Please use 915resolution as resolution modify tool for Intel graphic chipset."; return -1'
2479     fi
2480
2481     #a1# Output version of running grml
2482     alias grml-version='cat /etc/grml_version'
2483
2484     if check_com -c rebuildfstab ; then
2485         #a1# Rebuild /etc/fstab
2486         alias grml-rebuildfstab='rebuildfstab -v -r -config'
2487     fi
2488
2489     if check_com -c grml-debootstrap ; then
2490         alias debian2hd='print "Installing debian to harddisk is possible via using grml-debootstrap." ; return 1'
2491     fi
2492 }
2493 # }}}
2494
2495 # {{{ now run the functions
2496 isgrml && checkhome
2497 is4    && isgrml    && grmlstuff
2498 is4    && grmlcomp
2499 # }}}
2500
2501 # {{{ keephack
2502 is4 && xsource "/etc/zsh/keephack"
2503 # }}}
2504
2505 # {{{ wonderful idea of using "e" glob qualifier by Peter Stephenson
2506 # You use it as follows:
2507 # $ NTREF=/reference/file
2508 # $ ls -l *(e:nt:)
2509 # This lists all the files in the current directory newer than the reference file.
2510 # You can also specify the reference file inline; note quotes:
2511 # $ ls -l *(e:'nt ~/.zshenv':)
2512 is4 && nt() {
2513     if [[ -n $1 ]] ; then
2514         local NTREF=${~1}
2515     fi
2516     [[ $REPLY -nt $NTREF ]]
2517 }
2518 # }}}
2519
2520 # shell functions {{{
2521
2522 #f1# Provide csh compatibility
2523 setenv()  { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }  # csh compatibility
2524
2525 #f1# Reload an autoloadable function
2526 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
2527
2528 #f1# Reload zsh setup
2529 reload() {
2530     if [[ "$#*" -eq 0 ]] ; then
2531         [[ -r ~/.zshrc ]] && . ~/.zshrc
2532     else
2533         local fn
2534         for fn in "$@"; do
2535             unfunction $fn
2536             autoload -U $fn
2537         done
2538     fi
2539 }
2540 compdef _functions reload freload
2541
2542 #f1# List symlinks in detail (more detailed version of 'readlink -f' and 'whence -s')
2543 sll() {
2544     [[ -z "$1" ]] && printf 'Usage: %s <file(s)>\n' "$0" && return 1
2545     for i in "$@" ; do
2546         file=$i
2547         while [[ -h "$file" ]] ; do
2548             ls -l $file
2549             file=$(readlink "$file")
2550         done
2551     done
2552 }
2553
2554 # fast manual access
2555 if check_com qma ; then
2556     #f1# View the zsh manual
2557     manzsh()  { qma zshall "$1" }
2558     compdef _man qma
2559 else
2560     manzsh()  { /usr/bin/man zshall |  vim -c "se ft=man| se hlsearch" +/"$1" - ; }
2561     # manzsh()  { /usr/bin/man zshall |  most +/"$1" ; }
2562     # [[ -f ~/.terminfo/m/mostlike ]] && MYLESS='LESS=C TERMINFO=~/.terminfo TERM=mostlike less' || MYLESS='less'
2563     # manzsh()  { man zshall | $MYLESS -p $1 ; }
2564 fi
2565
2566 if check_com -c $PAGER ; then
2567     #f1# View Debian's changelog of a given package
2568     dchange() {
2569         if [[ -r /usr/share/doc/${1}/changelog.Debian.gz ]] ; then
2570             $PAGER /usr/share/doc/${1}/changelog.Debian.gz
2571         elif [[ -r /usr/share/doc/${1}/changelog.gz ]] ; then
2572             $PAGER /usr/share/doc/${1}/changelog.gz
2573         else
2574             if check_com -c aptitude ; then
2575                 echo "No changelog for package $1 found, using aptitude to retrieve it."
2576                 if isgrml ; then
2577                     aptitude -t unstable changelog ${1}
2578                 else
2579                     aptitude changelog ${1}
2580                 fi
2581             else
2582                 echo "No changelog for package $1 found, sorry."
2583                 return 1
2584             fi
2585         fi
2586     }
2587     _dchange() { _files -W /usr/share/doc -/ }
2588     compdef _dchange dchange
2589
2590     #f1# View Debian's NEWS of a given package
2591     dnews() {
2592         if [[ -r /usr/share/doc/${1}/NEWS.Debian.gz ]] ; then
2593             $PAGER /usr/share/doc/${1}/NEWS.Debian.gz
2594         else
2595             if [[ -r /usr/share/doc/${1}/NEWS.gz ]] ; then
2596                 $PAGER /usr/share/doc/${1}/NEWS.gz
2597             else
2598                 echo "No NEWS file for package $1 found, sorry."
2599                 return 1
2600             fi
2601         fi
2602     }
2603     _dnews() { _files -W /usr/share/doc -/ }
2604     compdef _dnews dnews
2605
2606     #f1# View upstream's changelog of a given package
2607     uchange() {
2608         if [[ -r /usr/share/doc/${1}/changelog.gz ]] ; then
2609             $PAGER /usr/share/doc/${1}/changelog.gz
2610         else
2611             echo "No changelog for package $1 found, sorry."
2612             return 1
2613         fi
2614     }
2615     _uchange() { _files -W /usr/share/doc -/ }
2616     compdef _uchange uchange
2617 fi
2618
2619 # zsh profiling
2620 profile() {
2621     ZSH_PROFILE_RC=1 $SHELL "$@"
2622 }
2623
2624 #f1# Edit an alias via zle
2625 edalias() {
2626     [[ -z "$1" ]] && { echo "Usage: edalias <alias_to_edit>" ; return 1 } || vared aliases'[$1]' ;
2627 }
2628 compdef _aliases edalias
2629
2630 #f1# Edit a function via zle
2631 edfunc() {
2632     [[ -z "$1" ]] && { echo "Usage: edfun <function_to_edit>" ; return 1 } || zed -f "$1" ;
2633 }
2634 compdef _functions edfunc
2635
2636 # use it e.g. via 'Restart apache2'
2637 #m# f6 Start() \kbd{/etc/init.d/\em{process}}\quad\kbd{start}
2638 #m# f6 Restart() \kbd{/etc/init.d/\em{process}}\quad\kbd{restart}
2639 #m# f6 Stop() \kbd{/etc/init.d/\em{process}}\quad\kbd{stop}
2640 #m# f6 Reload() \kbd{/etc/init.d/\em{process}}\quad\kbd{reload}
2641 #m# f6 Force-Reload() \kbd{/etc/init.d/\em{process}}\quad\kbd{force-reload}
2642 if [[ -d /etc/init.d || -d /etc/service ]] ; then
2643     __start_stop() {
2644         local action_="${1:l}"  # e.g Start/Stop/Restart
2645         local service_="$2"
2646         local param_="$3"
2647
2648         local service_target_="$(readlink /etc/init.d/$service_)"
2649         if [[ $service_target_ == "/usr/bin/sv" ]]; then
2650             # runit
2651             case "${action_}" in
2652                 start) if [[ ! -e /etc/service/$service_ ]]; then
2653                            $SUDO ln -s "/etc/sv/$service_" "/etc/service/"
2654                        else
2655                            $SUDO "/etc/init.d/$service_" "${action_}" "$param_"
2656                        fi ;;
2657                 # there is no reload in runits sysv emulation
2658                 reload) $SUDO "/etc/init.d/$service_" "force-reload" "$param_" ;;
2659                 *) $SUDO "/etc/init.d/$service_" "${action_}" "$param_" ;;
2660             esac
2661         else
2662             # sysvinit
2663             $SUDO "/etc/init.d/$service_" "${action_}" "$param_"
2664         fi
2665     }
2666
2667     for i in Start Restart Stop Force-Reload Reload ; do
2668         eval "$i() { __start_stop $i \"\$1\" \"\$2\" ; }"
2669     done
2670 fi
2671
2672 #f1# Provides useful information on globbing
2673 H-Glob() {
2674     echo -e "
2675     /      directories
2676     .      plain files
2677     @      symbolic links
2678     =      sockets
2679     p      named pipes (FIFOs)
2680     *      executable plain files (0100)
2681     %      device files (character or block special)
2682     %b     block special files
2683     %c     character special files
2684     r      owner-readable files (0400)
2685     w      owner-writable files (0200)
2686     x      owner-executable files (0100)
2687     A      group-readable files (0040)
2688     I      group-writable files (0020)
2689     E      group-executable files (0010)
2690     R      world-readable files (0004)
2691     W      world-writable files (0002)
2692     X      world-executable files (0001)
2693     s      setuid files (04000)
2694     S      setgid files (02000)
2695     t      files with the sticky bit (01000)
2696
2697   print *(m-1)          # Files modified up to a day ago
2698   print *(a1)           # Files accessed a day ago
2699   print *(@)            # Just symlinks
2700   print *(Lk+50)        # Files bigger than 50 kilobytes
2701   print *(Lk-50)        # Files smaller than 50 kilobytes
2702   print **/*.c          # All *.c files recursively starting in \$PWD
2703   print **/*.c~file.c   # Same as above, but excluding 'file.c'
2704   print (foo|bar).*     # Files starting with 'foo' or 'bar'
2705   print *~*.*           # All Files that do not contain a dot
2706   chmod 644 *(.^x)      # make all plain non-executable files publically readable
2707   print -l *(.c|.h)     # Lists *.c and *.h
2708   print **/*(g:users:)  # Recursively match all files that are owned by group 'users'
2709   echo /proc/*/cwd(:h:t:s/self//) # Analogous to >ps ax | awk '{print $1}'<"
2710 }
2711 alias help-zshglob=H-Glob
2712
2713 check_com -c qma && alias ?='qma zshall'
2714
2715 # grep for running process, like: 'any vim'
2716 any() {
2717     if [[ -z "$1" ]] ; then
2718         echo "any - grep for process(es) by keyword" >&2
2719         echo "Usage: any <keyword>" >&2 ; return 1
2720     else
2721         local STRING=$1
2722         local LENGTH=$(expr length $STRING)
2723         local FIRSCHAR=$(echo $(expr substr $STRING 1 1))
2724         local REST=$(echo $(expr substr $STRING 2 $LENGTH))
2725         ps xauwww| grep "[$FIRSCHAR]$REST"
2726     fi
2727 }
2728
2729 # After resuming from suspend, system is paging heavily, leading to very bad interactivity.
2730 # taken from $LINUX-KERNELSOURCE/Documentation/power/swsusp.txt
2731 [[ -r /proc/1/maps ]] && \
2732 deswap() {
2733     print 'Reading /proc/[0-9]*/maps and sending output to /dev/null, this might take a while.'
2734     cat $(sed -ne 's:.* /:/:p' /proc/[0-9]*/maps | sort -u | grep -v '^/dev/')  > /dev/null
2735     print 'Finished, running "swapoff -a; swapon -a" may also be useful.'
2736 }
2737
2738 # print hex value of a number
2739 hex() {
2740     [[ -n "$1" ]] && printf "%x\n" $1 || { print 'Usage: hex <number-to-convert>' ; return 1 }
2741 }
2742
2743 # calculate (or eval at all ;-)) with perl => p[erl-]eval
2744 # hint: also take a look at zcalc -> 'autoload zcalc' -> 'man zshmodules | less -p MATHFUNC'
2745 peval() {
2746     [[ -n "$1" ]] && CALC="$*" || print "Usage: calc [expression]"
2747     perl -e "print eval($CALC),\"\n\";"
2748 }
2749 functions peval &>/dev/null && alias calc=peval
2750
2751 # brltty seems to have problems with utf8 environment and/or font Uni3-Terminus16 under
2752 # certain circumstances, so work around it, no matter which environment we have
2753 brltty() {
2754     if [[ -z "$DISPLAY" ]] ; then
2755         consolechars -f /usr/share/consolefonts/default8x16.psf.gz
2756         command brltty "$@"
2757     else
2758         command brltty "$@"
2759     fi
2760 }
2761
2762 # just press 'asdf' keys to toggle between dvorak and us keyboard layout
2763 aoeu() {
2764     echo -n 'Switching to us keyboard layout: '
2765     [[ -z "$DISPLAY" ]] && $SUDO loadkeys us &>/dev/null || setxkbmap us &>/dev/null
2766     echo 'Done'
2767 }
2768 asdf() {
2769     echo -n 'Switching to dvorak keyboard layout: '
2770     [[ -z "$DISPLAY" ]] && $SUDO loadkeys dvorak &>/dev/null || setxkbmap dvorak &>/dev/null
2771     echo 'Done'
2772 }
2773 # just press 'asdf' key to toggle from neon layout to us keyboard layout
2774 uiae() {
2775     echo -n 'Switching to us keyboard layout: '
2776     setxkbmap us && echo 'Done' || echo 'Failed'
2777 }
2778
2779 # set up an ipv6 tunnel
2780 ipv6-tunnel() {
2781     case $1 in
2782         start)
2783             if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
2784                 print 'ipv6 tunnel already set up, nothing to be done.'
2785                 print 'execute: "ifconfig sit1 down ; ifconfig sit0 down" to remove ipv6-tunnel.' ; return 1
2786             else
2787                 [[ -n "$PUBLIC_IP" ]] || \
2788                     local PUBLIC_IP=$(ifconfig $(route -n | awk '/^0\.0\.0\.0/{print $8; exit}') | \
2789                                       awk '/inet addr:/ {print $2}' | tr -d 'addr:')
2790
2791                 [[ -n "$PUBLIC_IP" ]] || { print 'No $PUBLIC_IP set and could not determine default one.' ; return 1 }
2792                 local IPV6ADDR=$(printf "2002:%02x%02x:%02x%02x:1::1" $(print ${PUBLIC_IP//./ }))
2793                 print -n "Setting up ipv6 tunnel $IPV6ADDR via ${PUBLIC_IP}: "
2794                 ifconfig sit0 tunnel ::192.88.99.1 up
2795                 ifconfig sit1 add "$IPV6ADDR" && print done || print failed
2796             fi
2797             ;;
2798         status)
2799             if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
2800                 print 'ipv6 tunnel available' ; return 0
2801             else
2802                 print 'ipv6 tunnel not available' ; return 1
2803             fi
2804             ;;
2805         stop)
2806             if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
2807                 print -n 'Stopping ipv6 tunnel (sit0 + sit1): '
2808                 ifconfig sit1 down ; ifconfig sit0 down && print done || print failed
2809             else
2810                 print 'No ipv6 tunnel found, nothing to be done.' ; return 1
2811             fi
2812             ;;
2813         *)
2814             print "Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
2815             ;;
2816     esac
2817 }
2818
2819 # run dhclient for wireless device
2820 iwclient() {
2821     salias dhclient "$(wavemon -d | awk '/device/{print $2}')"
2822 }
2823
2824 # spawn a minimally set up ksh - useful if you want to umount /usr/.
2825 minimal-shell() {
2826     exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ksh
2827 }
2828
2829 # make a backup of a file
2830 bk() {
2831     cp -a "$1" "${1}_$(date --iso-8601=seconds)"
2832 }
2833
2834 # Switching shell safely and efficiently? http://www.zsh.org/mla/workers/2001/msg02410.html
2835 # bash() {
2836 #  NO_SWITCH="yes" command bash "$@"
2837 # }
2838 # restart () {
2839 #  exec $SHELL $SHELL_ARGS "$@"
2840 # }
2841
2842 # }}}
2843
2844 # log out? set timeout in seconds {{{
2845 # TMOUT=1800
2846 # do not log out in some specific terminals:
2847 #  if [[ "${TERM}" == ([Exa]term*|rxvt|dtterm|screen*) ]] ; then
2848 #    unset TMOUT
2849 #  fi
2850 # }}}
2851
2852 # {{{ make sure our environment is clean regarding colors
2853 for color in BLUE RED GREEN CYAN YELLOW MAGENTA WHITE ; unset $color
2854 # }}}
2855
2856 # source another config file if present {{{
2857 xsource "/etc/zsh/zshrc.local"
2858 xsource "${HOME}/.zshenv"
2859 # }}}
2860
2861 # "persistent history" {{{
2862 # just write important commands you always need to ~/.important_commands
2863 if [[ -r ~/.important_commands ]] ; then
2864     fc -R ~/.important_commands
2865 fi
2866 # }}}
2867
2868 ## genrefcard.pl settings {{{
2869 ### example: split functions-search 8,16,24,32
2870 #@# split functions-search 8
2871 ## }}}
2872
2873 # add variable to be able to check whether the file has been read {{{
2874 ZSHRC_GLOBAL_HAS_BEEN_READ=1
2875 # }}}
2876
2877 ## END OF FILE #################################################################
2878 # vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4