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 # Latest change: Die Mai 31 15:28:47 CEST 2005 [mika]
7 ################################################################################
8 # This file is sourced only for interactive shells. It
9 # should contain commands to set up aliases, functions,
10 # options, key bindings, etc.
12 # Global Order: zshenv, zprofile, zshrc, zlogin
13 ################################################################################
15 # {{{ check for version/system
16 # check for versions (compatibility reasons)
18 if [[ $ZSH_VERSION == 4.* ]]; then
27 if [[ $ZSH_VERSION == 4.<2->* ]]; then
36 if [ -f /etc/grml_version ] ; then
44 if [ -f /etc/grml_cd ] ; then
51 # change directory to home on first invocation of zsh
52 # important for rungetty -> autologin
53 # Thanks go to Bart Schaefer!
54 isgrml && checkhome() {
55 if [[ -z "$ALREADY_DID_CD_HOME" ]]; then
56 export ALREADY_DID_CD_HOME=$HOME
62 # {{{ set some variables
63 [[ -z "$EDITOR" ]] && EDITOR='vim'
64 [[ -z "$SHELL" ]] && SHELL='/bin/zsh'
65 [[ -f ~/.terminfo/m/mostlike ]] && MYLESS='LESS=C TERMINFO=~/.terminfo TERM=mostlike less' || MYLESS='less'
68 # Search path for the cd comman
71 # automatically remove duplicates from these arrays
72 typeset -U path cdpath fpath manpath
76 if [[ "$TERM" != emacs ]]; then
77 [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
78 [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
79 [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
80 [[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
81 [[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
82 [[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
84 [[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
85 [[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
86 [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
87 [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
88 [[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
89 [[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
92 [[ "$terminfo[kcuu1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
93 [[ "$terminfo[kcud1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
94 [[ "$terminfo[kcuf1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
95 [[ "$terminfo[kcub1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
96 [[ "$terminfo[khome]" == "
\eO"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
97 [[ "$terminfo[kend]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
98 [[ "$terminfo[khome]" == "
\eO"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
99 [[ "$terminfo[kend]" == "
\eO"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
102 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
103 # use emacs style per default
108 #if [[ "$TERM" == screen ]]; then
109 bindkey '\e[1~' beginning-of-line # home
110 bindkey '\e[4~' end-of-line # end
111 bindkey "^[[A" up-line-or-search # cursor up
112 bindkey "^[[B" down-line-or-search # <ESC>-
113 bindkey '^x' history-beginning-search-backward
115 # bindkey '\eq' push-line-or-edit
119 autoload -U zmv # who needs mmv or rename?
120 autoload history-search-end
122 alias run-help >&/dev/null && unalias run-help
123 autoload run-help # use via 'esc-h'
125 is4 && autoload -U compinit && compinit # completition system
126 is4 && autoload -U zed # use ZLE editor to edit a file or function
128 is4 && zmodload -i zsh/complist
129 is4 && zmodload -i zsh/deltochar
130 is4 && zmodload -i zsh/mathfunc
131 # Autoload zsh modules when they are referenced
132 is4 && zmodload -a zsh/stat stat
133 is4 && zmodload -a zsh/zpty zpty
134 is4 && zmodload -a zsh/zprof zprof
135 is4 && zmodload -ap zsh/mapfile mapfile
137 is4 && autoload -U insert-files && \
138 zle -N insert-files && \
139 bindkey "^Xf" insert-files # C-x-f
141 bindkey ' ' magic-space # also do history expansion on space
143 # press Esc-e for editing command line in $EDITOR or $VISUAL
144 is4 && autoload -U edit-command-line && \
145 zle -N edit-command-line && \
146 bindkey '\ee' edit-command-line
148 # press Esc-m for inserting last typed word again (thanks to caphuso!)
149 insert-last-typed-word() { zle insert-last-word -- 0 -1 }; \
150 zle -N insert-last-typed-word; bindkey "\em" insert-last-typed-word
152 # set command prediction from history, see 'man 1 zshcontrib'
153 is4 && autoload -U predict-on && \
154 zle -N predict-on && \
155 zle -N predict-off && \
156 bindkey "^X^Z" predict-on && \
157 bindkey "^Z" predict-off
160 # {{{ set some important options
164 setopt append_history # append history list to the history file (important for multiple parallel zsh sessions!)
165 is4 && setopt SHARE_HISTORY # import new commands from the history file also in other zsh-session
166 setopt extended_history # save each command's beginning timestamp and the duration to the history file
167 is4 && setopt histignorealldups # If a new command line being added to the history
168 # list duplicates an older one, the older command is removed from the list
169 setopt histignorespace # remove command lines from the history list when
170 # the first character on the line is a space
171 setopt histallowclobber # add `|' to output redirections in the history
173 setopt auto_cd # if a command is issued that can't be executed as a normal command,
174 # and the command is the name of a directory, perform the cd command to that directory
175 setopt correct # try to correct the spelling if possible
176 setopt extended_glob # in order to use #, ~ and ^ for filename generation
177 # grep word *~(*.gz|*.bz|*.bz2|*.zip|*.Z) ->
178 # -> searches for word not in compressed files
179 # don't forget to quote '^', '~' and '#'!
180 setopt NO_clobber # warning if file exists ('cat /dev/null > ~/.zshrc')
181 setopt notify # report the status of backgrounds jobs immediately
182 setopt hash_list_all # Whenever a command completion is attempted, make sure \
183 # the entire command path is hashed first.
184 setopt completeinword # not just at the end
185 # setopt nocheckjobs # don't warn me about bg processes when exiting
186 setopt nohup # and don't kill them, either
187 # setopt printexitvalue # alert me if something failed
188 # setopt dvorak # with spelling correction, assume dvorak kb
190 MAILCHECK=30 # mailchecks
191 REPORTTIME=5 # report about cpu-/system-/user-time of command if running longer than 5 secondes
192 watch=(notme root) # watch for everyone but me and root
196 export ZSHDIR=$HOME/.zsh
197 HISTFILE="$HOME/.zsh_history"
199 SAVEHIST=1000 # useful for setopt append_history
203 #precmd () { setopt promptsubst; [[ -o interactive ]] && jobs -l;
205 RPROMPT="%(?..:()% ${SCREENTITLE}"
209 # set screen window title if running in a screen
210 # get the name of the program currently running
211 if [[ "$TERM" == screen* ]]; then
212 local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}
213 echo -ne "\ek$CMD\e\\"
215 # set the screen title to "zsh" when sitting at a command prompt:
216 if [[ "$TERM" == screen* ]]; then
217 SCREENTITLE=$'%{\ekzsh\e\\%}'
223 EXITCODE="%(?..%?%1v )"
224 local BLUE="%{
\e[1;34m%}"
225 local RED="%{
\e[1;31m%}"
226 local GREEN="%{
\e[1;32m%}"
227 local CYAN="%{
\e[1;36m%}"
228 local NO_COLOUR="%{
\e[0m%}"
229 PS2='`%_> ' # secondary prompt, printed when the shell needs more information to complete a command.
230 PS3='?# ' # selection prompt used within a select loop.
231 PS4='+%N:%i:%_> ' # the execution trace prompt (setopt xtrace). default: '+%N:%i>'
233 # only if $GRMLPROMPT is set (e.g. via GRMLPROMPT='1') use the extended prompt
234 if ! [[ -z "$GRMLPROMPT" ]]; then
235 PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
236 ${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# "
238 if (( EUID != 0 )); then
239 PROMPT="${RED}${EXITCODE}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# " # primary prompt string
241 PROMPT="${BLUE}${EXITCODE}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# " # primary prompt string
246 # {{{ 'hash' some often used directories
247 hash -d deb=/var/cache/apt/archives
248 hash -d doc=/usr/share/doc
249 hash -d linux=/lib/modules/$(command uname -r)/build/
251 hash -d slog=/var/log/syslog
253 hash -d templ=/usr/share/doc/grml-templates
254 hash -d tt=/usr/share/doc/texttools-doc
259 alias la="ls -la --color=auto"
260 alias ll="ls -l --color=auto"
261 alias l="ls -lF --color=auto"
262 alias ls="ls --color=auto" # people are used to it, so...
264 alias cp='nocorrect cp' # no spelling correction on cp
265 alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
266 alias mv='nocorrect mv' # no spelling correction on mv
269 alias acs='apt-cache search'
270 alias agi='apt-get install'
271 alias acsh='apt-cache show'
272 alias au='apt-get update'
273 alias ag='apt-get upgrade'
274 alias adg='apt-get dist-upgrade'
275 alias ge='grep-excuses'
276 alias dbp='dpkg-buildpackage'
278 isgrmlcd && alias su='sudo su' # change to user root
279 alias tlog='tail -f /var/log/syslog' # take a look at the syslog
280 alias zshskel='source /etc/skel/.zshrc' # source skeleton zshrc
283 # {{{ Use hard limits, except for a smaller stack and no core dumps
286 limit core 0 # important for a live-cd-system
290 # {{{ completion stuff
291 # called later (via is4 && grmlcomp)
292 # use 'zstyle' for getting current settings
293 # press ^Xh (control-x h) for getting tags in context
295 zstyle ':completion:*:processes' command 'ps -au$USER' # on processes completion complete all user processes
296 zstyle ':completion:*:descriptions' format \
297 $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' # format on completion
298 zstyle ':completion:*' verbose yes # provide verbose completion information
299 zstyle ':completion:*:messages' format '%d'
300 zstyle ':completion:*:warnings' format \
301 $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
302 zstyle ':completion:*:matches' group 'yes' # separate matches into groups
303 zstyle ':completion:*:options' description 'yes' # describe options in full
304 zstyle ':completion:*:options' auto-description '%d'
305 zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
307 # activate color-completion(!)
308 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
312 # Ignore completion functions for commands you don't have:
313 # zstyle ':completion:*:functions' ignored-patterns '_*'
314 zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
316 zstyle ':completion:*' completer _complete _correct _approximate
317 zstyle ':completion:*:correct:*' insert-unambiguous true
318 # zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
319 # zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%}'
320 zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
321 zstyle ':completion:*:correct:*' original true
322 zstyle ':completion:correct:' prompt 'correct to:'
324 # allow one error for every three characters typed in approximate completer
325 zstyle -e ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
326 # zstyle ':completion:*:correct:*' max-errors 2 numeric
328 # match uppercase from lowercase
329 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
331 # command for process lists, the local web server details and host completion
332 hosts=(`hostname` grml.org)
333 zstyle '*' hosts $hosts
334 zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
336 # offer indexes before parameters in subscripts
337 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
339 # insert all expansions for expand completer
340 zstyle ':completion:*:expand:*' tag-order all-expansions
342 # ignore duplicate entries
343 zstyle ':completion:*:history-words' stop yes
344 zstyle ':completion:*:history-words' remove-all-dups yes
345 zstyle ':completion:*:history-words' list false
346 zstyle ':completion:*:history-words' menu yes
348 # filename suffixes to ignore during completion (except after rm command)
349 # zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.(o|c~|old|pro|zwc)' '*~'
351 # Don't complete backup files as executables
352 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
354 # If there are more than 5 options, allow selecting from a menu with
355 # arrows (case insensitive completion!).
356 # zstyle ':completion:*-case' menu select=5
357 zstyle ':completion:*' menu select=5
359 # zstyle ':completion:*:*:kill:*' verbose no
360 # zstyle ':completion:*:sudo:*' command-path /usr/local/sbin /usr/local/bin \
361 # /usr/sbin /usr/bin /sbin /bin /usr/X11R6/bin
364 [ -d $ZSHDIR/cache ] && zstyle ':completion:*' use-cache yes && \
365 zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
367 # use ~/.ssh/known_hosts for completion
369 # _myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
370 # zstyle ':completion:*' hosts $_myhosts
371 [ -f "$HOME/.ssh/known_hosts" ] && \
372 hosts=(${${${(f)"$(<$HOME/.ssh/known_hosts)"}%%\ *}%%,*}) && \
373 zstyle ':completion:*:hosts' hosts $hosts
375 # simple completion for fbset (switch resolution on console)
376 _fbmodes() { compadd 640x480-60 640x480-72 640x480-75 640x480-90 640x480-100 768x576-75 800x600-48-lace 800x600-56 800x600-60 800x600-70 800x600-72 800x600-75 800x600-90 800x600-100 1024x768-43-lace 1024x768-60 1024x768-70 1024x768-72 1024x768-75 1024x768-90 1024x768-100 1152x864-43-lace 1152x864-47-lace 1152x864-60 1152x864-70 1152x864-75 1152x864-80 1280x960-75-8 1280x960-75 1280x960-75-32 1280x1024-43-lace 1280x1024-47-lace 1280x1024-60 1280x1024-70 1280x1024-74 1280x1024-75 1600x1200-60 1600x1200-66 1600x1200-76 }
377 compdef _fbmodes fbset
379 # use generic completion system for programs not yet defined:
380 compdef _gnu_generic tail head feh cp mv gpg df stow uname ipacsum fetchipac
382 # Debian specific stuff
383 # zstyle ':completion:*:*:lintian:*' file-patterns '*.deb'
384 zstyle ':completion:*:*:linda:*' file-patterns '*.deb'
386 _debian_rules() { words=(make -f debian/rules) _make }
387 compdef _debian_rules debian/rules # type debian/rules <TAB> inside a source package
389 # see upgrade function in this file
390 compdef _hosts upgrade
396 # people should use 'grml-x'!
397 if ! [ -r /etc/X11/xorg.conf ] ; then
398 isgrmlcd && alias startx='echo -e "Please use the script \"grml-x\" for starting the X Window System.\n If you want to use startx anyway please call \"/usr/X11R6/bin/startx\"."; return -1'
401 # load language settings - wrapper around the main script
403 grml-setlang $* && zsh
406 _grml-lang() { compadd at de en ; }
407 compdef _grml-lang grml-lang
409 # _grml-x() { compadd fluxbox ion2 ion3 pekwm ratpoison twm wmi wmii ; }
410 # compdef _grml-x grml-x
411 _grml-x() { local arguments wm
412 wm=(fluxbox ion2 ion3 pekwm pwm2 pwm3 ratpoison twm wmi wmii)
414 '-display:display for xserver:(7 8)'
415 '-force[force creation of xconfig file]' '-help:display help'
416 '-hsync:horizontal sync frequencies (<number>):(28 `seq 30 5 95` 96)'
417 '-mode:resolution-mode for xserver (<width>x<height> - e.g. 1024x768)]:(1920x1440 1600x1200 1400x1050 1280x102
418 4 1280x960 1024x768 800x600 640x480)'
419 '-module:module for xserver :(`cd /usr/X11R6/lib/modules/drivers && ls *.o | sed 's/_drv.o//'`)'
420 '-nostart:do not start X server'
421 '-vsync:vertical sync frequencies (<number>):(43 `seq 45 5 70` 72)'
422 '-xserver:xserver used for creation of xconfig file:(XFree86 X.org)'
423 ':window manager:($wm)'
425 #'-vsync:use specified vsync (xx.0 - xx.0):(`seq -f '%g.0' 50 5 70`)'
426 #'-hsync:use specified hsync (xx.0 - xx.0):(28.0 `seq -f '%g.0' 30 5 95` 96.0)'
427 _arguments -s $arguments
429 compdef _grml-x grml-x
431 grml-wallpaper() { Esetroot -scale /usr/share/grml/$* }
433 dirs=(. /usr/share/grml/)
434 _description files expl 'set desktop wallpaper on grml system'
435 _files "$expl[@]" -W dirs -g '*.{jpg,png}(-.)'
437 compdef _grml-wallpaper grml-wallpaper
439 alias grml-version='cat /etc/grml_version'
443 # {{{ now run the functions
445 is4 && isgrml && grmlstuff
450 [ -r /etc/zsh/keephack ] && is4 && source /etc/zsh/keephack
453 # {{{ wonderful idea of using "e" glob qualifier by Peter Stephenson
454 # You use it as follows:
455 # $ NTREF=/reference/file
457 # This lists all the files in the current directory newer than the reference file.
458 # You can also specify the reference file inline; note quotes:
459 # $ ls -l *(e:'nt ~/.zshenv':)
464 [[ $REPLY -nt $NTREF ]]
468 # shell functions {{{
469 setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } # csh compatibility
470 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
471 manzsh() { man zshall | $MYLESS -p $1 ; }
473 # use it e.g. via 'restart apache2'
474 # for i in start restart stop reload ;
476 # eval "$i() { /etc/init.d/\$1 $i ; }"
478 for i in Start Restart Stop Reload ; do
479 if [ UID != 0 ] ; then
482 eval "$i() { $RUNASROOT /etc/init.d/\$1 ${i:l} ; }"
484 # now the completion for this:
485 # compdef "_files -W /etc/init.d/" Stop Start Reload Restart
486 compctl -g "$(echo /etc/init.d/*(:t))" Start Restart Stop Reload
489 # source another config file if present {{{
490 if [ -r /etc/zsh/zshrc.local ]; then
491 source /etc/zsh/zshrc.local
495 ## END OF FILE #################################################################
496 # vim:foldmethod=marker