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.
11 # Global Order: zshenv, zprofile, zshrc, zlogin
12 ################################################################################
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).
21 # Here is what they mean:
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'
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.
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@@)
56 # All of these tags (except for m and o) take two arguments, the first
57 # within the tag, the other after the tag:
59 # #<tag><section># <comment>
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:
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
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@@.
88 # just execute 'ZSH_PROFILE_RC=1 zsh' and run 'zprof' to get the details
89 if [[ $ZSH_PROFILE_RC -gt 0 ]] ; then
94 # setting some default values {{{
97 NOPRECMD=${NOPRECMD:-0}
101 # {{{ check for version/system
102 # check for versions (compatibility reasons)
104 [[ $ZSH_VERSION == <4->* ]] && return 0
109 [[ $ZSH_VERSION == 4.<1->* || $ZSH_VERSION == <5->* ]] && return 0
114 [[ $ZSH_VERSION == 4.<2->* || $ZSH_VERSION == <5->* ]] && return 0
119 [[ $ZSH_VERSION == 4.2.<5->* || $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
124 [[ $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
128 #f1# Checks whether or not you're running grml
130 [[ -f /etc/grml_version ]] && return 0
134 #f1# Checks whether or not you're running a grml cd
136 [[ -f /etc/grml_cd ]] && return 0
141 #f1# Checks whether or not you're running grml-small
143 [[ ${${${(f)"$(</etc/grml_version)"}%% *}##*-} == 'small' ]] && return 0 ; return 1
146 isgrmlsmall() { return 1 }
149 #f1# are we running within an utf environment?
151 case "$LANG $CHARSET $LANGUAGE" in
158 # check for user, if not running as root set $SUDO to sudo
159 (( EUID != 0 )) && SUDO='sudo' || SUDO=''
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
171 # check for zsh v3.1.7+
173 if ! [[ ${ZSH_VERSION} == 3.1.<7->* \
174 || ${ZSH_VERSION} == 3.<2->.<->* \
175 || ${ZSH_VERSION} == <4->.<->* ]] ; then
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'
183 printf '-!- However, you are running zsh version %s.\n' "$ZSH_VERSION"
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'
188 printf '-!- DO NOT EXPECT THIS TO WORK FLAWLESSLY!\n'
189 printf '-!- If it does today, you'\''ve been lucky.\n'
191 printf '-!- Ye been warned!\n'
194 function zstyle() { : }
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. :-)
206 if [[ ${1} == '-c' ]] ; then
213 if (( ${#argv} != 1 )) ; then
214 printf 'usage: check_com [-c] <command>\n' >&2
218 if (( comonly > 0 )) ; then
219 [[ -n ${commands[$1]} ]] && return 0
223 if [[ -n ${commands[$1]} ]] \
224 || [[ -n ${functions[$1]} ]] \
225 || [[ -n ${aliases[$1]} ]] \
226 || [[ -n ${reswords[(r)$1]} ]] ; then
234 # creates an alias and precedes the command with
235 # sudo if $EUID is not zero.
237 local only=0 ; local multi=0
238 while [[ ${1} == -* ]] ; do
242 (--) shift ; break ;;
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'
251 (*) printf "unkown option: '%s'\n" "${1}" ; return 1 ;;
256 if (( ${#argv} > 1 )) ; then
257 printf 'Too many arguments %s\n' "${#argv}"
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}"
272 # a "print -l ${(u)foo}"-workaround for pre-4.2.0 shells
274 # Where foo is the *name* of the parameter you want printed.
275 # Note that foo is no typo; $foo would be wrong here!
282 if [[ -z ${parameter} ]] ; then
283 printf 'usage: uprint <parameter>\n'
287 for w in ${(P)parameter} ; do
288 [[ -z ${(M)u:#${w}} ]] && u=( ${u} ${w} )
291 builtin print -l ${u}
295 # Check if we can read given files and source those we can.
297 if (( ${#argv} < 1 )) ; then
298 printf 'usage: xsource FILE(s)...\n' >&2
302 while (( ${#argv} > 0 )) ; do
303 [[ -r ${1} ]] && source ${1}
309 # Check if we can read a given file and 'cat(1)' it.
311 if (( ${#argv} != 1 )) ; then
312 printf 'usage: xcat FILE\n' >&2
316 [[ -r ${1} ]] && cat ${1}
320 # Remove these functions again, they are of use only in these
321 # setup files. This should be called at the end of .zshrc.
324 funcs=(salias xcat xsource xunfunction zrcautoload)
326 for func in $funcs ; do
327 [[ -n ${functions[$func]} ]] \
333 # autoload wrapper - use this one instead of autoload directly
334 function zrcautoload() {
335 setopt local_options extended_glob
341 for fdir in ${fpath} ; do
342 [[ -e ${fdir}/${ffile} ]] && (( ffound = 1 ))
345 (( ffound == 0 )) && return 1
346 if [[ $ZSH_VERSION == 3.1.<6-> || $ZSH_VERSION == <4->* ]] ; then
347 autoload -U ${ffile} || return 1
349 autoload ${ffile} || return 1
356 # Load is-at-least() for more precise version checks {{{
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 }
365 if [[ -z "$LANG" ]] ; then
366 xsource "/etc/default/locale"
369 export LANG=${LANG:-en_US.iso885915}
370 for var in LC_ALL LC_MESSAGES ; do
371 [[ -n ${(P)var} ]] && export $var
374 xsource "/etc/sysconfig/keyboard"
376 TZ=$(xcat /etc/timezone)
379 # check for potentially old files in 'completion.d' {{{
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
405 # {{{ set some variables
406 if check_com -c vim ; then
408 export EDITOR=${EDITOR:-vim}
410 export EDITOR=${EDITOR:-vi}
414 export PAGER=${PAGER:-less}
417 export MAIL=${MAIL:-/var/mail/$USER}
419 # if we don't set $SHELL then aterm, rxvt,.. will use /bin/sh or /bin/bash :-/
420 export SHELL='/bin/zsh'
422 # color setup for ls:
423 check_com -c dircolors && eval $(dircolors -b)
425 # set width of man pages to 80 for more convenient reading
426 # export MANWIDTH=${MANWIDTH:-80}
428 # Search path for the cd command
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
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}
446 # automatically remove duplicates from these arrays
447 typeset -U path cdpath fpath manpath
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
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
475 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
476 # use emacs style per default:
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>-
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
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
504 # just type 'cd ...' to get 'cd ../..'
505 # rationalise-dot() {
506 # if [[ $LBUFFER == *.. ]] ; then
512 # zle -N rationalise-dot
513 # bindkey . rationalise-dot
515 # bindkey '\eq' push-line-or-edit
517 ## toggle the ,. abbreviation feature on/off
518 # NOABBREVIATION: default abbreviation-state
519 # 0 - enabled (default)
521 NOABBREVIATION=${NOABBREVIATION:-0}
523 grml_toggle_abbrev() {
524 if (( ${NOABBREVIATION} > 0 )) ; then
531 zle -N grml_toggle_abbrev
532 bindkey '^xA' grml_toggle_abbrev
536 # a generic accept-line wrapper {{{
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.
542 # For a broader description, see:
543 # <http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html>
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.
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
555 function Accept-Line() {
556 setopt localoptions noksharrays
561 zstyle -a ":acceptline:${alcontext}" actions subs
563 (( ${#subs} < 1 )) && return 0
566 for sub in ${subs} ; do
567 [[ ${sub} == 'accept-line' ]] && sub='.accept-line'
570 (( aldone > 0 )) && break
574 function Accept-Line-getdefault() {
577 zstyle -s ":acceptline:${alcontext}" default_action default_action
578 case ${default_action} in
580 printf ".accept-line"
583 printf ${default_action}
588 function accept-line() {
589 setopt localoptions noksharrays
592 local buf com fname format msg default_action
596 cmdline=(${(z)BUFFER})
600 zstyle -t ":acceptline:${alcontext}" rehash \
601 && [[ -z ${commands[$com]} ]] \
604 if [[ -n ${reswords[(r)$com]} ]] \
605 || [[ -n ${aliases[$com]} ]] \
606 || [[ -n ${functions[$com]} ]] \
607 || [[ -n ${builtins[$com]} ]] \
608 || [[ -n ${commands[$com]} ]] ; then
610 # there is something sensible to execute, just do it.
614 default_action=$(Accept-Line-getdefault)
615 zstyle -T ":acceptline:${alcontext}" call_default \
616 && zle ${default_action}
620 if [[ -o correct ]] \
621 || [[ -o correctall ]] \
622 && [[ -n ${functions[$fname]} ]] ; then
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.
634 default_action=$(Accept-Line-getdefault)
635 zstyle -T ":acceptline:${alcontext}" call_default \
636 && zle ${default_action}
640 # prepare warning message for the user, configurable via zstyle.
641 zstyle -s ":acceptline:${alcontext}" compwarnfmt msg
643 if [[ -z ${msg} ]] ; then
644 msg="%c will not execute and completion %f exists."
647 zformat -f msg "${msg}" "c:${com}" "f:${fname}"
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
658 default_action=$(Accept-Line-getdefault)
659 zstyle -T ":acceptline:${alcontext}" call_default \
660 && zle ${default_action}
664 # If we got this far, the commandline only contains whitespace, or is empty.
668 default_action=$(Accept-Line-getdefault)
669 zstyle -T ":acceptline:${alcontext}" call_default \
670 && zle ${default_action}
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
685 setopt interactivecomments
687 # key # value (#d additional doc string)
693 'G' '|& grep --color=auto'
695 'Hl' ' --help |& less -r' #d (Display help in pager)
699 'N' '&>/dev/null' #d (No Output)
700 'R' '| tr A-z N-za-m' #d (ROT13)
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"'
718 'co' "./configure && make && sudo make install"
719 'CH' "./configure --help"
720 'conkeror' 'firefox -chrome chrome://conkeror/content'
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'
735 '600' 'chmod u+rw-x,g-rwx,o-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'
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 ({..}) { }'
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'
755 'D' 'export DISPLAY=:0.0'
756 'mp' 'mplayer -vo xv -fs -zoom'
762 if (( NOABBREVIATION > 0 )) ; then
763 LBUFFER="${LBUFFER},."
767 matched_chars='[.-|_a-zA-Z0-9]#'
768 LBUFFER=${LBUFFER%%(#m)[.-|_a-zA-Z0-9]#}
769 LBUFFER+=${abk[$MATCH]:-$MATCH}
773 bindkey ",." globalias
777 zrcautoload zmv # who needs mmv or rename?
778 zrcautoload history-search-end
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 '*?[]^()~#{}='
785 # print 'Notice: no url-quote-magic available :('
787 alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic'
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'
794 if zrcautoload compinit && compinit 2>/dev/null ; then
795 compinit 2>/dev/null || print 'Notice: no compinit available :('
797 print 'Notice: no compinit available :('
802 is4 && zrcautoload zed # use ZLE editor to edit a file or function
805 for mod in complist deltochar mathfunc ; do
806 zmodload -i zsh/${mod} 2>/dev/null || print "Notice: no ${mod} available :("
809 # autoload zsh modules when they are referenced
817 while (( ${#tmpargs} > 0 )) ; do
818 zmodload -${tmpargs[1]} zsh/${tmpargs[2]} ${tmpargs[2]}
824 if is4 && zrcautoload insert-files && zle -N insert-files ; then
826 bindkey "^Xf" insert-files # C-x-f
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
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
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
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
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
855 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
856 _bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
859 #k# Insert a timestamp on the command line (yyyy-mm-dd)
860 bindkey '^Ed' _bkdate
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;
866 #k# Insert last typed word
867 bindkey "\em" insert-last-typed-word
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
876 #k# Shortcut for \kbd{fg<enter>}
877 bindkey -s '^z' "fg\n"
879 # press ctrl-q to quote line:
881 # zle beginning-of-line
883 # # RBUFFER="'$RBUFFER'"
884 # RBUFFER=${(q)RBUFFER}
887 # zle -N mquote && bindkey '^q' mquote
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"
894 zle -N sudo-command-line
896 #k# Put the current command line into a \kbd{sudo} call
897 bindkey "^Os" sudo-command-line
899 ### jump behind the first word on the cmdline.
900 ### useful to add options.
901 function jump_after_first_word() {
905 if (( ${#words} <= 1 )) ; then
908 CURSOR=${#${words[1]}}
911 zle -N jump_after_first_word
913 bindkey '^x1' jump_after_first_word
917 # {{{ set some important options
918 # Please update these tags, if you change the umask settings below.
920 #o# r_umaskstr rwxrwxr-x
922 #o# umaskstr rwxr-xr-x
923 (( EUID != 0 )) && umask 002 || umask 022
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.
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
959 # define word separators (for stuff like backward-word, forward-word, backward-kill-word,..)
960 # WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' # the default
962 # WORDCHARS='*?_[]~=&;!#$%^(){}'
963 # WORDCHARS='${WORDCHARS:s@/@}'
965 # only slash should be considered as a word separator:
966 slash-backward-kill-word() {
967 local WORDCHARS="${WORDCHARS:s@/@}"
969 zle backward-kill-word
971 zle -N slash-backward-kill-word
973 #k# Kill everything in a word up to its last \kbd{/}
974 bindkey '\ev' slash-backward-kill-word
983 HISTFILE=$HOME/.zsh_history
984 isgrmlcd && HISTSIZE=500 || HISTSIZE=5000
985 isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history
989 # dirstack handling {{{
991 DIRSTACKSIZE=${DIRSTACKSIZE:-20}
992 DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs}
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
1002 builtin print -l ${(u)dirstack} >! ${DIRSTACKFILE}
1004 uprint dirstack >! ${DIRSTACKFILE}
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
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'
1023 if [[ "$PERCENT" -lt 20 ]] ; then
1024 PERCENT="warning: ${PERCENT}%%"
1026 PERCENT="${PERCENT}%%"
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}%}"
1044 BLUE=$'%{\e[1;34m%}'
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%}'
1056 # gather version control information for inclusion in a prompt {{{
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.
1063 for i in {0..9} ; do
1064 unset VCS_INFO_message_${i}_
1066 zstyle ':vcs_info:*' enable false
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.
1073 # we will only be using one variable, so let the code know now.
1074 zstyle ':vcs_info:*' max-exports 1
1076 # vcs_info() documentation:
1080 # This functionality requires zsh version >= 4.1.*.
1085 # To load vcs_info(), copy this file to your $fpath[] and do:
1086 # % autoload -Uz vcs_info && vcs_info
1088 # To work, vcs_info() needs 'setopt prompt_subst' in your setup.
1093 # To get vcs_info() working quickly (including colors), you can do the
1094 # following (assuming, you loaded vcs_info() properly - see above):
1096 # % RED=$'%{\e[31m%}'
1097 # % GR=$'%{\e[32m%}'
1098 # % MA=$'%{\e[35m%}'
1099 # % YE=$'%{\e[33m%}'
1102 # % zstyle ':vcs_info:*' actionformats \
1103 # "${MA}(${NC}%s${MA})${YE}-${MA}[${GR}%b${YE}|${RED}%a${MA}]${NC} "
1105 # % zstyle ':vcs_info:*' formats \
1106 # "${MA}(${NC}%s${MA})${Y}-${MA}[${GR}%b${MA}]${NC}%} "
1108 # % zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YE}%r"
1110 # % precmd () { vcs_info }
1111 # % PS1='${MA}[${GR}%n${MA}] ${MA}(${RED}%!${MA}) ${YE}%3~ ${VCS_INFO_message_0_}${NC}%# '
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.
1118 # Now call the 'vcs_info_printsys' utility from the command line:
1120 # % vcs_info_printsys
1121 # # list of supported version control backends:
1122 # # disabled systems are prefixed by a hash sign (#)
1133 # # flavours (cannot be used in the disable style; they
1134 # # are disabled with their master [git-svn -> git]):
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:
1143 # % zstyle ':vcs_info:*' disable bzr cdv darcs mtn svk tla
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.
1149 # For more control, read the reference below.
1154 # The vcs_info() feature can be configured via zstyle.
1156 # First, the context in which we are working:
1157 # :vcs_info:<vcs-string>:<user-context>
1159 # ...where <vcs-string> is one of:
1160 # - git, git-svn, git-p4, hg, darcs, bzr, cdv, mtn, svn, cvs, svk or tla.
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).
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.
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.
1176 # You may *not* use 'print_systems_' as a user-context string, because it
1177 # is used internally.
1179 # You can of course use ':vcs_info:*' to match all VCSs in all
1180 # user-contexts at once.
1182 # Another special context is 'formats', which is used by the
1183 # vcs_info_lastmsg() utility function (see below).
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().
1220 # The use-simple style is only available for the bzr backend.
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)
1229 # disable (empty list)
1231 # use-prompt-escapes true
1234 # In normal formats and actionformats, the following replacements
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'.
1247 # In branchformat these replacements are done:
1248 # %b - the branch name
1249 # %r - the current revision number
1251 # Not all vcs backends have to support all replacements.
1252 # nvcsformat does not perform *any* replacements. It is just a string.
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.
1266 # FUNCTION DESCRIPTIONS (public API):
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).
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.
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.
1285 # All functions named VCS_INFO_* are for internal use only.
1288 # VARIABLE DESCRIPTION:
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.)
1304 # Don't use vcs_info at all (even though it's in your prompt):
1305 # % zstyle ':vcs_info:*' enable false
1307 # Disable the backends for bzr and svk:
1308 # % zstyle ':vcs_info:*' disable bzr svk
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]'
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
1318 # Display the revision number in yellow for bzr and svn:
1319 # % zstyle ':vcs_info:(svn|bzr):*' branchformat '%b%{'${fg[yellow]}'%}:%r'
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.
1324 # Here is how to print the vcs infomation as a command:
1325 # % alias vcsi='vcs_info command; vcs_info_lastmsg'
1327 # This way, you can even define different formats for output via
1328 # vcs_info_lastmsg() in the ':vcs_info:command:*' namespace.
1332 VCS_INFO_adjust () { #{{{
1333 [[ -n ${vcs_comm[overwrite_name]} ]] && vcs=${vcs_comm[overwrite_name]}
1337 VCS_INFO_check_com () { #{{{
1338 (( ${+commands[$1]} )) && [[ -x ${commands[$1]} ]] && return 0
1342 VCS_INFO_formats () { # {{{
1343 setopt localoptions noksharrays
1344 local action=$1 branch=$2 base=$3
1348 if [[ -n ${action} ]] ; then
1349 zstyle -a ":vcs_info:${vcs}:${usercontext}" actionformats msgs
1350 (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b|%a]-'
1352 zstyle -a ":vcs_info:${vcs}:${usercontext}" formats msgs
1353 (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b]-'
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})"
1364 VCS_INFO_maxexports () { #{{{
1365 local -ix maxexports
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'
1375 VCS_INFO_nvcsformats () { #{{{
1376 setopt localoptions noksharrays
1379 if [[ $1 == 'preinit' ]] ; then
1383 zstyle -a ":vcs_info:${v:-$vcs}:${c:-$usercontext}" nvcsformats msgs
1384 (( ${#msgs} > maxexports )) && msgs[${maxexports},-1]=()
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
1393 (( ${+functions[chpwd]} )) && unfunction chpwd
1395 cd $1 2>/dev/null && pwd
1399 VCS_INFO_reposub () { #{{{
1400 setopt localoptions extendedglob
1401 local base=${1%%/##}
1403 [[ ${PWD} == ${base}/* ]] || {
1407 printf '%s' ${PWD#$base/}
1411 VCS_INFO_set () { #{{{
1412 setopt localoptions noksharrays
1415 if [[ $1 == '--clear' ]] ; then
1416 for i in {0..9} ; do
1417 unset VCS_INFO_message_${i}_
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}_=
1425 VCS_INFO_nvcsformats $2
1428 (( ${#msgs} - 1 < 0 )) && return 0
1429 for i in {0..$(( ${#msgs} - 1 ))} ; do
1431 typeset -gx VCS_INFO_message_${i}_=${msgs[$j]}
1436 # information gathering
1437 VCS_INFO_bzr_get_data () { # {{{
1438 setopt localoptions noksharrays
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]}%% *}
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})"
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}"
1461 VCS_INFO_cdv_get_data () { # {{{
1464 cdvbase=${vcs_comm[basedir]}
1465 VCS_INFO_formats '' "${cdvbase:t}" "${cdvbase}"
1469 VCS_INFO_cvs_get_data () { # {{{
1470 local cvsbranch cvsbase basename
1473 while [[ -d "${cvsbase}/../CVS" ]]; do
1474 cvsbase="${cvsbase}/.."
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}"
1485 VCS_INFO_darcs_get_data () { # {{{
1488 darcsbase=${vcs_comm[basedir]}
1489 VCS_INFO_formats '' "${darcsbase:t}" "${darcsbase}"
1493 VCS_INFO_git_getaction () { #{{{
1494 local gitaction='' gitdir=$1
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
1503 elif [[ -f "${tmp}/applying" ]] ; then
1506 gitaction="am/rebase"
1508 printf '%s' ${gitaction}
1513 for tmp in "${gitdir}/rebase-merge/interactive" \
1514 "${gitdir}/.dotest-merge/interactive" ; do
1515 if [[ -f "${tmp}" ]] ; then
1516 printf '%s' "rebase-i"
1521 for tmp in "${gitdir}/rebase-merge" \
1522 "${gitdir}/.dotest-merge" ; do
1523 if [[ -d "${tmp}" ]] ; then
1524 printf '%s' "rebase-m"
1529 if [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
1534 if [[ -f "${gitdir}/BISECT_LOG" ]] ; then
1535 printf '%s' "bisect"
1541 VCS_INFO_git_getbranch () { #{{{
1542 local gitbranch gitdir=$1
1543 local gitsymref='git symbolic-ref HEAD'
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)"
1553 elif [[ -f "${gitdir}/rebase-merge/interactive" ]] \
1554 || [[ -d "${gitdir}/rebase-merge" ]] ; then
1555 gitbranch="$(< ${gitdir}/rebase-merge/head-name)"
1557 elif [[ -f "${gitdir}/.dotest-merge/interactive" ]] \
1558 || [[ -d "${gitdir}/.dotest-merge" ]] ; then
1559 gitbranch="$(< ${gitdir}/.dotest-merge/head-name)"
1562 gitbranch="$(${(z)gitsymref} 2> /dev/null)"
1564 if [[ $? -ne 0 ]] ; then
1565 gitbranch="$(git describe --exact-match HEAD 2>/dev/null)"
1567 if [[ $? -ne 0 ]] ; then
1568 gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
1573 printf '%s' "${gitbranch##refs/heads/}"
1577 VCS_INFO_git_get_data () { # {{{
1578 setopt localoptions extendedglob
1579 local gitdir gitbase gitbranch gitaction
1581 gitdir=${vcs_comm[gitdir]}
1582 gitbranch="$(VCS_INFO_git_getbranch ${gitdir})"
1584 if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then
1589 gitaction="$(VCS_INFO_git_getaction ${gitdir})"
1590 gitbase=${PWD%/${$( git rev-parse --show-prefix )%/##}}
1591 VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}"
1595 VCS_INFO_hg_get_data () { # {{{
1596 local hgbranch hgbase
1598 hgbase=${vcs_comm[basedir]}
1599 hgbranch=$(< ${hgbase}/.hg/branch)
1600 VCS_INFO_formats '' "${hgbranch}" "${hgbase}"
1604 VCS_INFO_mtn_get_data () { # {{{
1605 local mtnbranch mtnbase
1607 mtnbase=${vcs_comm[basedir]}
1608 mtnbranch=${${(M)${(f)"$( mtn status )"}:#(#s)Current branch:*}/*: /}
1609 VCS_INFO_formats '' "${mtnbranch}" "${mtnbase}"
1613 VCS_INFO_svk_get_data () { # {{{
1614 local svkbranch svkbase
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}"
1623 VCS_INFO_svn_get_data () { # {{{
1624 setopt localoptions noksharrays
1625 local svnbase svnbranch
1629 while [[ -d "${svnbase}/../.svn" ]]; do
1630 svnbase="${svnbase}/.."
1632 svnbase="$(VCS_INFO_realpath ${svnbase})"
1633 svninfo=( ${${${(M)${(f)"$( svn info )"}:#(#s)(URL|Revision)*}/*: /}/*\//} )
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}"
1641 VCS_INFO_tla_get_data () { # {{{
1642 local tlabase tlabranch
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}"
1652 VCS_INFO_detect_by_dir() { #{{{
1654 local basedir="." realbasedir
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]} ]] && \
1663 [[ -d ${basedir}/${dirname} ]] && break
1666 basedir=${basedir}/..
1667 realbasedir="$(VCS_INFO_realpath ${basedir})"
1670 [[ ${realbasedir} == "/" ]] && return 1
1671 vcs_comm[basedir]=${realbasedir}
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'
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'
1689 VCS_INFO_cvs_detect() { #{{{
1690 VCS_INFO_check_com svn || return 1
1691 [[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0
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'
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
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'
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'
1726 VCS_INFO_svk_detect() { #{{{
1727 setopt localoptions noksharrays extendedglob
1732 VCS_INFO_check_com svk || return 1
1733 [[ -f ~/.svk/config ]] || return 1
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
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
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
1755 [[ -n ${vcs_comm[basedir]} ]] && \
1756 [[ -n ${vcs_comm[branch]} ]] && \
1757 [[ -n ${vcs_comm[revision]} ]] && return 0
1761 VCS_INFO_svn_detect() { #{{{
1762 VCS_INFO_check_com svn || return 1
1763 [[ -d ".svn" ]] && return 0
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
1774 vcs_info_printsys () { # {{{
1775 vcs_info print_systems_
1778 vcs_info_lastmsg () { # {{{
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}_}}
1787 print -n ${(P)${:-VCS_INFO_message_${i}_}}
1795 local -a VCSs disabled
1796 local -x vcs usercontext
1801 VCSs=(git hg bzr darcs svk mtn svn cvs cdv tla)
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}
1811 print -l '# flavours (cannot be used in the disable style; they' \
1812 '# are disabled with their master [git-svn -> git]):' \
1817 [[ -z ${usercontext} ]] && usercontext=default
1819 (*) [[ -z ${usercontext} ]] && usercontext=$1
1823 zstyle -T ":vcs_info:${vcs}:${usercontext}" "enable" || {
1824 [[ -n ${VCS_INFO_message_0_} ]] && VCS_INFO_set --clear
1827 zstyle -a ":vcs_info:${vcs}:${usercontext}" "disable" disabled
1831 for vcs in ${VCSs} ; do
1832 [[ -n ${(M)disabled:#${vcs}} ]] && continue
1834 VCS_INFO_${vcs}_detect && (( found = 1 )) && break
1837 (( found == 0 )) && {
1842 VCS_INFO_${vcs}_get_data || {
1851 VCS_INFO_set --nvcs preinit
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] "
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"
1868 if zrcautoload promptinit && promptinit 2>/dev/null ; then
1869 promptinit # people should be able to use their favourite prompt
1871 print 'Notice: no promptinit available :('
1876 # make sure to use right prompt only when not running a command
1877 is41 && setopt transient_rprompt
1879 is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
1880 [[ $NOPRECMD -gt 0 ]] && return 0
1881 # update VCS information
1884 # allow manual overwriting of RPROMPT
1885 if [[ -n $RPROMPT ]] ; then
1886 [[ $TERM == screen* ]] && print -nP "\ekzsh\e\\"
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
1894 RPROMPT="%(?..:()% ${PERCENT}${SCREENTITLE}"
1895 # RPROMPT="${PERCENT}${SCREENTITLE}"
1897 RPROMPT="%(?..:()% ${SCREENTITLE}"
1898 # RPROMPT="${SCREENTITLE}"
1901 # adjust title of xterm
1902 # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
1905 print -Pn "\e]0;%n@%m: %~\a"
1910 # preexec() => a function running before every command
1911 is4 && [[ $NOPRECMD -eq 0 ]] && \
1913 [[ $NOPRECMD -gt 0 ]] && return 0
1914 # set hostname if not running on host with name 'grml'
1915 if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != $(hostname) ]] ; then
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\\"
1925 # set the screen title to "zsh" when sitting at the command prompt:
1926 if [[ "$TERM" == screen* ]] ; then
1927 SCREENTITLE=$'%{\ekzsh\e\\%}'
1931 # adjust title of xterm
1934 print -Pn "\e]0;%n@%m: $1\a"
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>'
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)
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_}'"%# "
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%<< %# "
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_}'"%# "
1963 PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
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%<< %\# "
1974 # {{{ 'hash' some often used directories
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
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"
1994 [[ -r /etc/grml/screenrc_grml ]] && alias screen='/usr/bin/screen -c /etc/grml/screenrc_grml'
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'
2010 alias ls='ls -b -CF'
2017 alias mdstat='cat /proc/mdstat'
2018 alias ...='cd ../../'
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)""
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
2030 #a1# Execute \kbd{rmdir}
2032 #a1# Execute \kbd{rmdir}
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'"
2039 # make sure it is not assigned yet
2040 [[ $(whence -w utf2iso &>/dev/null) == 'utf2iso: alias' ]] && unalias utf2iso
2044 for ENV in $(env | command grep -i '.utf') ; do
2045 eval export "$(echo $ENV | sed 's/UTF-8/iso885915/ ; s/utf8/iso885915/')"
2050 # make sure it is not assigned yet
2051 [[ $(whence -w iso2utf &>/dev/null) == 'iso2utf: alias' ]] && unalias 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/')"
2060 # set up software synthesizer via speakup
2062 if [ -x /usr/sbin/swspeak-setup ] ; then
2063 setopt singlelinezle
2066 /usr/sbin/swspeak-setup $@
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?"
2073 setopt singlelinezle
2076 nice -n -20 speechd-up
2078 flite -o play -t "Finished setting up software synthesizer"
2083 # I like clean prompt, so provide simple way to get that
2084 check_com 0 || alias 0='return 0'
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'
2090 # get top 10 shell commands:
2091 alias top10='print -l ? ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
2093 # truecrypt; use e.g. via 'truec /dev/ice /mnt/ice' or 'truec -i'
2094 if check_com -c truecrypt ; then
2096 alias truec='truecrypt --mount-options "rw,sync,dirsync,users,uid=1000,gid=users,umask=077,utf8" '
2098 alias truec='truecrypt --mount-options "rw,sync,dirsync,users,uid=1000,gid=users,umask=077" '
2102 #f1# Hints for the use of zsh on grml
2104 print "$bg[white]$fg[black]
2105 zsh-help - hints for use of zsh on grml
2106 =======================================$reset_color"
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
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
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.
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.
2129 For information regarding zsh start at http://grml.org/zsh/
2131 Take a look at grml'\''s zsh refcard:
2132 % xpdf =(zcat /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)
2134 Check out the main zsh refcard:
2135 % '$BROWSER' http://www.bash2zsh.com/zsh_refcard/refcard.pdf
2137 And of course visit the zsh-lovers:
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
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
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
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"
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'
2187 #f3# Execute \kbd{apt-get update \&\& }\\&\quad \kbd{apt-get dist-upgrade}
2189 if [[ -z "$1" ]] ; then
2190 $SUDO apt-get update
2191 $SUDO apt-get -u upgrade
2193 ssh $1 $SUDO apt-get update
2194 # ask before the upgrade
2196 ssh $1 $SUDO apt-get --no-act upgrade
2197 echo -n 'Process the upgrade?'
2199 if [[ $dummy == "y" ]] ; then
2200 ssh $1 $SUDO apt-get -u upgrade --yes
2205 # get a root shell as normal user in live-cd mode:
2206 if isgrmlcd && [[ $UID -ne 0 ]] ; then
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
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'
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.
2230 Please use the wodim binary instead' ; return 1"
2234 # get_tw_cli has been renamed into get_3ware
2235 if check_com -c get_3ware ; then
2237 echo 'Warning: get_tw_cli has been renamed into get_3ware. Invoking get_3ware for you.'>&2
2242 # I hate lacking backward compatibility, so provide an alternative therefore
2243 if ! check_com -c apache2-ssl-certificate ; then
2245 apache2-ssl-certificate() {
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:'
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
2258 Run "grml-tips ssl-certificate" if you need further instructions.
2264 # {{{ Use hard limits, except for a smaller stack and no core dumps
2266 is425 && limit stack 8192
2267 isgrmlcd && limit core 0 # important for a live-cd-system
2271 # {{{ completion system
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
2277 # TODO: This could use some additional information
2279 # allow one error for every three characters typed in approximate completer
2280 zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
2282 # don't complete backup files as executables
2283 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)'
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
2290 # activate color-completion
2291 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
2293 # format on completion
2294 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
2296 # complete 'cd -<tab>' with menu
2297 zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
2299 # insert all expansions for expand completer
2300 zstyle ':completion:*:expand:*' tag-order all-expansions
2301 zstyle ':completion:*:history-words' list false
2304 zstyle ':completion:*:history-words' menu yes
2306 # ignore duplicate entries
2307 zstyle ':completion:*:history-words' remove-all-dups yes
2308 zstyle ':completion:*:history-words' stop yes
2310 # match uppercase from lowercase
2311 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
2313 # separate matches into groups
2314 zstyle ':completion:*:matches' group 'yes'
2315 zstyle ':completion:*' group-name ''
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
2321 # don't use any menus at all
2325 zstyle ':completion:*:messages' format '%d'
2326 zstyle ':completion:*:options' auto-description '%d'
2328 # describe options in full
2329 zstyle ':completion:*:options' description 'yes'
2331 # on processes completion complete all user processes
2332 zstyle ':completion:*:processes' command 'ps -au$USER'
2334 # offer indexes before parameters in subscripts
2335 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
2337 # provide verbose completion information
2338 zstyle ':completion:*' verbose true
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
2345 # set format for warnings
2346 zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
2348 # define files to ignore for zcompile
2349 zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
2350 zstyle ':completion:correct:' prompt 'correct to: %e'
2352 # Ignore completion functions for commands you don't have:
2353 zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
2355 # Provide more processes in completion of programs like killall:
2356 zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
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
2363 # run rehash on completion so new installed program are found automatically:
2365 (( CURRENT == 1 )) && rehash
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
2375 # try to be smart about when to use what completer...
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)
2382 if [[ $words[1] == (rm|mv) ]] ; then
2383 reply=(_complete _files)
2385 reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
2390 # zstyle ':completion:*' completer _complete _correct _approximate
2391 # zstyle ':completion:*' expand prefix suffix
2393 # complete shell aliases
2394 # zstyle ':completion:*' completer _expand_alias _complete _approximate
2396 # command for process lists, the local web server details and host completion
2397 zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
2400 [[ -d $ZSHDIR/cache ]] && zstyle ':completion:*' use-cache yes && \
2401 zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
2403 # host completion /* add brackets as vim can't parse zsh's complex cmdlines 8-) {{{ */
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=()
2418 zstyle ':completion:*:hosts' hosts $hosts
2419 # zstyle '*' hosts $hosts
2421 # specify your logins:
2423 # {grml,grml1}@foo.invalid
2424 # grml-devel@bar.invalid
2427 # {fred,root}@foo.invalid
2430 # zstyle ':completion:*:my-accounts' users-hosts $my_accounts
2431 # zstyle ':completion:*:other-accounts' users-hosts $other_accounts
2433 # specify specific port/service settings:
2434 # telnet_users_hosts_ports=(
2437 # @mail-server:{smtp,pop3}
2439 # @proxy-server:8000
2441 # zstyle ':completion:*:*:telnet:*' users-hosts-ports $telnet_users_hosts_ports
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
2447 # see upgrade function in this file
2448 compdef _hosts upgrade
2454 # people should use 'grml-x'!
2456 if [[ -e /etc/X11/xorg.conf ]] ; then
2457 [[ -x /usr/bin/startx ]] && /usr/bin/startx "$@" || /usr/X11R6/bin/startx "$@"
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\"."
2467 if [[ -e /etc/X11/xorg.conf ]] ; then
2468 [[ -x /usr/bin/xinit ]] && /usr/bin/xinit || /usr/X11R6/bin/xinit
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\"."
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'
2481 #a1# Output version of running grml
2482 alias grml-version='cat /etc/grml_version'
2484 if check_com -c rebuildfstab ; then
2485 #a1# Rebuild /etc/fstab
2486 alias grml-rebuildfstab='rebuildfstab -v -r -config'
2489 if check_com -c grml-debootstrap ; then
2490 alias debian2hd='print "Installing debian to harddisk is possible via using grml-debootstrap." ; return 1'
2495 # {{{ now run the functions
2497 is4 && isgrml && grmlstuff
2502 is4 && xsource "/etc/zsh/keephack"
2505 # {{{ wonderful idea of using "e" glob qualifier by Peter Stephenson
2506 # You use it as follows:
2507 # $ NTREF=/reference/file
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':)
2513 if [[ -n $1 ]] ; then
2516 [[ $REPLY -nt $NTREF ]]
2520 # shell functions {{{
2522 #f1# Provide csh compatibility
2523 setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } # csh compatibility
2525 #f1# Reload an autoloadable function
2526 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
2528 #f1# Reload zsh setup
2530 if [[ "$#*" -eq 0 ]] ; then
2531 [[ -r ~/.zshrc ]] && . ~/.zshrc
2540 compdef _functions reload freload
2542 #f1# List symlinks in detail (more detailed version of 'readlink -f' and 'whence -s')
2544 [[ -z "$1" ]] && printf 'Usage: %s <file(s)>\n' "$0" && return 1
2547 while [[ -h "$file" ]] ; do
2549 file=$(readlink "$file")
2554 # fast manual access
2555 if check_com qma ; then
2556 #f1# View the zsh manual
2557 manzsh() { qma zshall "$1" }
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 ; }
2566 if check_com -c $PAGER ; then
2567 #f1# View Debian's changelog of a given package
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
2574 if check_com -c aptitude ; then
2575 echo "No changelog for package $1 found, using aptitude to retrieve it."
2577 aptitude -t unstable changelog ${1}
2579 aptitude changelog ${1}
2582 echo "No changelog for package $1 found, sorry."
2587 _dchange() { _files -W /usr/share/doc -/ }
2588 compdef _dchange dchange
2590 #f1# View Debian's NEWS of a given package
2592 if [[ -r /usr/share/doc/${1}/NEWS.Debian.gz ]] ; then
2593 $PAGER /usr/share/doc/${1}/NEWS.Debian.gz
2595 if [[ -r /usr/share/doc/${1}/NEWS.gz ]] ; then
2596 $PAGER /usr/share/doc/${1}/NEWS.gz
2598 echo "No NEWS file for package $1 found, sorry."
2603 _dnews() { _files -W /usr/share/doc -/ }
2604 compdef _dnews dnews
2606 #f1# View upstream's changelog of a given package
2608 if [[ -r /usr/share/doc/${1}/changelog.gz ]] ; then
2609 $PAGER /usr/share/doc/${1}/changelog.gz
2611 echo "No changelog for package $1 found, sorry."
2615 _uchange() { _files -W /usr/share/doc -/ }
2616 compdef _uchange uchange
2621 ZSH_PROFILE_RC=1 $SHELL "$@"
2624 #f1# Edit an alias via zle
2626 [[ -z "$1" ]] && { echo "Usage: edalias <alias_to_edit>" ; return 1 } || vared aliases'[$1]' ;
2628 compdef _aliases edalias
2630 #f1# Edit a function via zle
2632 [[ -z "$1" ]] && { echo "Usage: edfun <function_to_edit>" ; return 1 } || zed -f "$1" ;
2634 compdef _functions edfunc
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
2644 local action_="${1:l}" # e.g Start/Stop/Restart
2648 local service_target_="$(readlink /etc/init.d/$service_)"
2649 if [[ $service_target_ == "/usr/bin/sv" ]]; then
2651 case "${action_}" in
2652 start) if [[ ! -e /etc/service/$service_ ]]; then
2653 $SUDO ln -s "/etc/sv/$service_" "/etc/service/"
2655 $SUDO "/etc/init.d/$service_" "${action_}" "$param_"
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_" ;;
2663 $SUDO "/etc/init.d/$service_" "${action_}" "$param_"
2667 for i in Start Restart Stop Force-Reload Reload ; do
2668 eval "$i() { __start_stop $i \"\$1\" \"\$2\" ; }"
2672 #f1# Provides useful information on globbing
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)
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}'<"
2711 alias help-zshglob=H-Glob
2713 check_com -c qma && alias ?='qma zshall'
2715 # grep for running process, like: 'any vim'
2717 if [[ -z "$1" ]] ; then
2718 echo "any - grep for process(es) by keyword" >&2
2719 echo "Usage: any <keyword>" >&2 ; return 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"
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 ]] && \
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.'
2738 # print hex value of a number
2740 [[ -n "$1" ]] && printf "%x\n" $1 || { print 'Usage: hex <number-to-convert>' ; return 1 }
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'
2746 [[ -n "$1" ]] && CALC="$*" || print "Usage: calc [expression]"
2747 perl -e "print eval($CALC),\"\n\";"
2749 functions peval &>/dev/null && alias calc=peval
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
2754 if [[ -z "$DISPLAY" ]] ; then
2755 consolechars -f /usr/share/consolefonts/default8x16.psf.gz
2762 # just press 'asdf' keys to toggle between dvorak and us keyboard layout
2764 echo -n 'Switching to us keyboard layout: '
2765 [[ -z "$DISPLAY" ]] && $SUDO loadkeys us &>/dev/null || setxkbmap us &>/dev/null
2769 echo -n 'Switching to dvorak keyboard layout: '
2770 [[ -z "$DISPLAY" ]] && $SUDO loadkeys dvorak &>/dev/null || setxkbmap dvorak &>/dev/null
2773 # just press 'asdf' key to toggle from neon layout to us keyboard layout
2775 echo -n 'Switching to us keyboard layout: '
2776 setxkbmap us && echo 'Done' || echo 'Failed'
2779 # set up an ipv6 tunnel
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
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:')
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
2799 if ifconfig sit1 2>/dev/null | grep -q 'inet6 addr: 2002:.*:1::1' ; then
2800 print 'ipv6 tunnel available' ; return 0
2802 print 'ipv6 tunnel not available' ; return 1
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
2810 print 'No ipv6 tunnel found, nothing to be done.' ; return 1
2814 print "Usage: ipv6-tunnel [start|stop|status]">&2 ; return 1
2819 # run dhclient for wireless device
2821 salias dhclient "$(wavemon -d | awk '/device/{print $2}')"
2824 # spawn a minimally set up ksh - useful if you want to umount /usr/.
2826 exec env -i ENV="/etc/minimal-shellrc" HOME="$HOME" TERM="$TERM" ksh
2829 # make a backup of a file
2831 cp -a "$1" "${1}_$(date --iso-8601=seconds)"
2834 # Switching shell safely and efficiently? http://www.zsh.org/mla/workers/2001/msg02410.html
2836 # NO_SWITCH="yes" command bash "$@"
2839 # exec $SHELL $SHELL_ARGS "$@"
2844 # log out? set timeout in seconds {{{
2846 # do not log out in some specific terminals:
2847 # if [[ "${TERM}" == ([Exa]term*|rxvt|dtterm|screen*) ]] ; then
2852 # {{{ make sure our environment is clean regarding colors
2853 for color in BLUE RED GREEN CYAN YELLOW MAGENTA WHITE ; unset $color
2856 # source another config file if present {{{
2857 xsource "/etc/zsh/zshrc.local"
2858 xsource "${HOME}/.zshenv"
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
2868 ## genrefcard.pl settings {{{
2869 ### example: split functions-search 8,16,24,32
2870 #@# split functions-search 8
2873 # add variable to be able to check whether the file has been read {{{
2874 ZSHRC_GLOBAL_HAS_BEEN_READ=1
2877 ## END OF FILE #################################################################
2878 # vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4