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: Son Okt 08 01:46:31 CEST 2006 [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 # check for user, if not running as root set $SUDO to sudo
52 (( EUID != 0 )) && SUDO='sudo' || SUDO=''
54 # change directory to home on first invocation of zsh
55 # important for rungetty -> autologin
56 # Thanks go to Bart Schaefer!
57 isgrml && checkhome() {
58 if [[ -z "$ALREADY_DID_CD_HOME" ]]; then
59 export ALREADY_DID_CD_HOME=$HOME
65 # {{{ set some variables
66 [[ -z "$EDITOR" ]] && export EDITOR='vim'
67 [[ -z "$SHELL" ]] && export SHELL='/bin/zsh'
68 [[ -z "$MAIL" ]] && export MAIL="/var/mail/$USER"
69 [[ -f ~/.terminfo/m/mostlike ]] && MYLESS='LESS=C TERMINFO=~/.terminfo TERM=mostlike less' || MYLESS='less'
70 [[ -x /usr/bin/dircolors ]] && eval `dircolors -b`
72 # Search path for the cd comman
75 # automatically remove duplicates from these arrays
76 typeset -U path cdpath fpath manpath
80 if [[ "$TERM" != emacs ]]; then
81 [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
82 [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
83 [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
84 [[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
85 [[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
86 [[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
87 [[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
88 [[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
89 [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
90 [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
91 [[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
92 [[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
94 [[ "$terminfo[kcuu1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
95 [[ "$terminfo[kcud1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
96 [[ "$terminfo[kcuf1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
97 [[ "$terminfo[kcub1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
98 [[ "$terminfo[khome]" == "
\eO"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
99 [[ "$terminfo[kend]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
100 [[ "$terminfo[khome]" == "
\eO"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
101 [[ "$terminfo[kend]" == "
\eO"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
104 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
105 # use emacs style per default
110 #if [[ "$TERM" == screen ]]; then
111 bindkey '\e[1~' beginning-of-line # home
112 bindkey '\e[4~' end-of-line # end
113 bindkey "^[[A" up-line-or-search # cursor up
114 bindkey "^[[B" down-line-or-search # <ESC>-
115 bindkey '^x' history-beginning-search-backward # alternative ways of searching the shell history
116 # bindkey -s '^L' "|less\n" # ctrl-L pipes to less
117 # bindkey -s '^B' " &\n" # ctrl-B runs it in the background
118 # if terminal type is set to 'rxvt':
119 bindkey '\e[7~' beginning-of-line # home
120 bindkey '\e[8~' end-of-line # end
123 # bindkey '\eq' push-line-or-edit
127 autoload -U zmv # who needs mmv or rename?
128 autoload history-search-end
130 # we don't want to quote/espace URLs on our own...
131 # avoid 'url-quote-magic: function definition file not found' on some older boxes
132 if [ -f /usr/share/zsh/$ZSH_VERSION/functions/Zle/url-quote-magic ] ; then
133 autoload -U url-quote-magic
134 zle -N self-insert url-quote-magic
137 alias run-help >&/dev/null && unalias run-help
138 autoload run-help # use via 'esc-h'
140 is4 && autoload -U compinit && compinit # completition system
141 is4 && autoload -U zed # use ZLE editor to edit a file or function
143 is4 && zmodload -i zsh/complist
144 is4 && zmodload -i zsh/deltochar
145 is4 && zmodload -i zsh/mathfunc
146 # autoload zsh modules when they are referenced
147 is4 && zmodload -a zsh/stat stat
148 is4 && zmodload -a zsh/zpty zpty
149 is4 && zmodload -a zsh/zprof zprof
150 is4 && zmodload -ap zsh/mapfile mapfile
152 is4 && autoload -U insert-files && \
153 zle -N insert-files && \
154 bindkey "^Xf" insert-files # C-x-f
156 bindkey ' ' magic-space # also do history expansion on space
157 bindkey '\ei' menu-complete # menu completion via esc-i
159 # press esc-e for editing command line in $EDITOR or $VISUAL
160 is4 && autoload -U edit-command-line && \
161 zle -N edit-command-line && \
162 bindkey '\ee' edit-command-line
164 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
165 _bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
166 bindkey '\C-ed' _bkdate
169 # press esc-m for inserting last typed word again (thanks to caphuso!)
170 insert-last-typed-word() { zle insert-last-word -- 0 -1 }; \
171 zle -N insert-last-typed-word; bindkey "\em" insert-last-typed-word
173 # set command prediction from history, see 'man 1 zshcontrib'
174 # is4 && autoload -U predict-on && \
175 # zle -N predict-on && \
176 # zle -N predict-off && \
177 # bindkey "^X^Z" predict-on && \
178 # bindkey "^Z" predict-off
180 # put job into foreground via ctrl-z:
181 bindkey -s '^z' "fg\n"
183 # press ctrl-q to quote line:
185 # zle beginning-of-line
187 # # RBUFFER="'$RBUFFER'"
188 # RBUFFER=${(q)RBUFFER}
191 # zle -N mquote && bindkey '^q' mquote
193 # run command line as user root via sudo:
194 _sudo-command-line() {
195 [[ $BUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER"
197 zle -N sudo-command-line _sudo-command-line
198 bindkey "^Os" sudo-command-line
201 # {{{ set some important options
205 setopt append_history # append history list to the history file (important for multiple parallel zsh sessions!)
206 is4 && setopt SHARE_HISTORY # import new commands from the history file also in other zsh-session
207 setopt extended_history # save each command's beginning timestamp and the duration to the history file
208 is4 && setopt histignorealldups # If a new command line being added to the history
209 # list duplicates an older one, the older command is removed from the list
210 setopt histignorespace # remove command lines from the history list when
211 # the first character on the line is a space
212 # setopt histallowclobber # add `|' to output redirections in the history
213 # setopt NO_clobber # warning if file exists ('cat /dev/null > ~/.zshrc')
214 setopt auto_cd # if a command is issued that can't be executed as a normal command,
215 # and the command is the name of a directory, perform the cd command to that directory
216 setopt extended_glob # in order to use #, ~ and ^ for filename generation
217 # grep word *~(*.gz|*.bz|*.bz2|*.zip|*.Z) ->
218 # -> searches for word not in compressed files
219 # don't forget to quote '^', '~' and '#'!
220 setopt notify # report the status of backgrounds jobs immediately
221 setopt hash_list_all # Whenever a command completion is attempted, make sure \
222 # the entire command path is hashed first.
223 setopt completeinword # not just at the end
224 # setopt nocheckjobs # don't warn me about bg processes when exiting
225 setopt nohup # and don't kill them, either
226 # setopt printexitvalue # alert me if something failed
227 # setopt dvorak # with spelling correction, assume dvorak kb
228 setopt auto_pushd # make cd push the old directory onto the directory stack.
229 setopt nonomatch # try to avoid the 'zsh: no matches found...'
230 setopt nobeep # avoid "beep"ing
232 MAILCHECK=30 # mailchecks
233 REPORTTIME=5 # report about cpu-/system-/user-time of command if running longer than 5 secondes
234 watch=(notme root) # watch for everyone but me and root
236 # define word separators (for stuff like backward-word, forward-word, backward-kill-word,..)
237 # WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' # the default
239 # WORDCHARS='*?_[]~=&;!#$%^(){}'
240 # WORDCHARS='${WORDCHARS:s@/@}'
242 # only slash should be considered as a word separator:
243 slash-backward-kill-word() {
244 local WORDCHARS="${WORDCHARS:s@/@}"
246 zle backward-kill-word
248 zle -N slash-backward-kill-word
249 bindkey '
\ev' slash-backward-kill-word # press esc-v to delete a word until its last '/' (not the same as ctrl-w!)
253 export ZSHDIR=$HOME/.zsh
254 HISTFILE=$HOME/.zsh_history
255 isgrmlcd && HISTSIZE=500 || HISTSIZE=5000
256 isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history
259 # {{{ display battery status on right side of prompt via running 'BATTERY=1 zsh'
260 if [ -n "$BATTERY" ] ; then
261 if [ -x =acpi ] ; then
262 PERCENT="${(C)${(s| |)$(acpi 2>/dev/null)}[4]}"
263 [ -z "$PERCENT" ] && PERCENT='acpi not present'
264 if [ "${PERCENT%%%}" -lt 20 ] ; then
265 PERCENT="warning: ${PERCENT}%"
272 autoload promptinit ; promptinit # people should be able to use their favourite prompt
273 # precmd() => a function which is executed just before each prompt
274 # precmd () { setopt promptsubst; [[ -o interactive ]] && jobs -l;
275 # run 'NOPRECMD=1 zsh' to disable the precmd + preexec commands
276 is4 && ! [[ -n "$NOPRECMD" ]] && precmd () {
277 if [ -n "$BATTERY" ] ; then
278 RPROMPT="%(?..:()% ${PERCENT}${SCREENTITLE}"
280 RPROMPT="%(?..:()% ${SCREENTITLE}"
282 # adjust title of xterm
283 # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
284 case $TERM in (xterm*|rxvt)
285 print -Pn "\e]0;%n@%m: %~\a"
290 # chpwd () => a function which is executed whenever the directory is changed
292 # preexec() => a function running before every command
293 is4 && ! [[ -n "$NOPRECMD" ]] && preexec () {
294 # set screen window title if running in a screen
295 # get the name of the program currently running and hostname of local machine
296 local HOSTNAME=$(hostname)
297 if [[ "$HOSTNAME" != grml ]] ; then
300 if [[ "$TERM" == screen* ]]; then
301 # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} # dont't use hostname
302 local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
303 echo -ne "\ek$CMD\e\\"
305 # set the screen title to "zsh" when sitting at the command prompt:
306 if [[ "$TERM" == screen* ]]; then
307 SCREENTITLE=$'%{\ekzsh\e\\%}'
311 # adjust title of xterm
312 case $TERM in (xterm*|rxvt)
313 print -Pn "\e]0;%n@%m: $1\a"
318 EXITCODE="%(?..%?%1v )"
319 local BLUE="%{
\e[1;34m%}"
320 local RED="%{
\e[1;31m%}"
321 local GREEN="%{
\e[1;32m%}"
322 local CYAN="%{
\e[1;36m%}"
323 local WHITE="%{
\e[1;37m%}"
324 local NO_COLOUR="%{
\e[0m%}"
325 PS2='`%_> ' # secondary prompt, printed when the shell needs more information to complete a command.
326 PS3='?# ' # selection prompt used within a select loop.
327 PS4='+%N:%i:%_> ' # the execution trace prompt (setopt xtrace). default: '+%N:%i>'
329 # set variable debian_chroot if running in a chroot with /etc/debian_chroot
330 if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
331 debian_chroot=$(cat /etc/debian_chroot)
334 # don't use colors on dumb terminals (like emacs):
335 if [[ "$TERM" == dumb ]] ; then
336 PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< %# "
338 # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended prompt
339 # set variable identifying the chroot you work in (used in the prompt below)
340 if [[ -n "$GRMLPROMPT" ]]; then
341 PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
342 ${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# "
344 if (( EUID != 0 )); then
345 PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# " # primary prompt string
347 PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# " # primary prompt string
352 # if we are inside a grml-chroot set a specific prompt theme
353 if [ -n "$GRML_CHROOT" ] ; then
354 PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "
358 # {{{ 'hash' some often used directories
359 hash -d deb=/var/cache/apt/archives
360 hash -d doc=/usr/share/doc
361 hash -d linux=/lib/modules/$(command uname -r)/build/
363 hash -d slog=/var/log/syslog
365 hash -d templ=/usr/share/doc/grml-templates
366 hash -d tt=/usr/share/doc/texttools-doc
371 if [ $UID = 0 ] ; then
372 [ -r /etc/grml/screenrc ] && alias screen='/usr/bin/screen -c /etc/grml/screenrc'
373 elif [ -r $HOME/.screenrc ] ; then
374 alias screen="/usr/bin/screen -c $HOME/.screenrc"
376 [ -r /etc/grml/screenrc_grml ] && alias screen='/usr/bin/screen -c /etc/grml/screenrc_grml'
379 if ls --help 2>/dev/null |grep -- --color= >/dev/null && [ "$TERM" != dumb ] ; then
380 alias ls='ls -b -CF --color=auto' # do we have GNU ls with color-support?
381 alias la='ls -la --color=auto'
382 alias ll='ls -l --color=auto'
383 alias lh='ls -hAl --color=auto'
384 alias l='ls -lF --color=auto'
393 alias cp='nocorrect cp' # no spelling correction on cp
394 alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
395 alias mv='nocorrect mv' # no spelling correction on mv
396 alias rm='nocorrect rm' # no spelling correction on rm
401 alias swspeak="setopt singlelinezle ; unsetopt prompt_cr ; export PS1='%m%# ' ; speechd-up" # set up software synth.
403 # truecrypt; use e.g. via 'truec /dev/ice' /mnt/ice' or 'truec -i'
404 if [ -x /usr/sbin/truecrypt ] ; then
405 alias truec='truecrypt --mount-options "rw,sync,dirsync,users,uid=1000,gid=users,umask=077" '
408 zsh-help(){print "$bg[white]$fg[black]
409 zsh-help - hints for use of zsh on grml
410 =======================================$reset_color
412 Main configuration of zsh happens in /etc/zsh/zshrc (global)
413 and /etc/skel/.zshrc which is copied to \$HOME/.zshrc once.
414 The files are part of the package grml-etc, if you want to
415 use them on a non-grml-system just get the tar.gz from
416 http://grml.org/repos/
418 If you want to stay in sync with zsh configuration of grml
419 run 'ln -sf /etc/skel/.zshrc \$HOME/.zshrc' and configure
420 your own stuff in \$HOME/.zshrc.local. System wide configuration
421 without touching configuration files of grml can take place
422 in /etc/zsh/zshrc.local.
424 If you want to use the configuration of user grml also when
425 running as user root just run 'zshskel' which will source
426 the file /etc/skel/.zshrc.
428 For information regarding zsh start at http://grml.org/zsh/
430 Take a look at grml's zsh refcard:
431 % xpdf =(zcat /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)
433 Check out the main zsh refcard:
434 % $BROWSER http://www.bash2zsh.com/zsh_refcard/refcard.pdf
436 And of course visit the zsh-lovers:
439 You can adjust some options through environment variables when
440 invoking zsh without having to edit configuration files.
441 Basically meant for bash users who are not used to the power of
444 \"NOCOR=1 zsh\" => deactivate automatic correction
445 \"NOMENU=1 zsh\" => do not use menu completion (note: use strg-d for completion instead!)
446 \"NOPRECMD=1 zsh\" => disable the precmd + preexec commands (set GNU screen title)
447 \"BATTERY=1 zsh\" => activate battery status (via acpi) on right side of prompt
449 Please report wishes + bugs to the grml-team: http://grml.org/bugs/
450 Enjoy your grml system with the zsh!$reset_color"
454 if [ -r /etc/debian_version ] ; then
455 alias acs="apt-cache search"
456 alias acsh="apt-cache show"
457 alias adg="$SUDO apt-get dist-upgrade"
458 alias agi="$SUDO apt-get install"
459 alias ag="$SUDO apt-get upgrade"
460 alias au="$SUDO apt-get update"
461 alias dbp="dpkg-buildpackage"
462 alias ge="grep-excuses"
464 isgrmlcd && alias su="sudo su" # change to user root
465 alias tlog="tail -f /var/log/syslog" # take a look at the syslog
466 alias zshskel="source /etc/skel/.zshrc" # source skeleton zshrc
469 # if cdrecord is a symlink (to wodim) or isn't present at all warn:
470 if [ -L /usr/bin/cdrecord -o ! -x =cdrecord ] ; then
471 if [ -x =wodim ] ; then
472 alias cdrecord="echo 'cdrecord is not provided under its original name by Debian anymore.
473 See #377109 in the BTS of Debian for more details.
475 Please use the wodim binary instead' ; return 1"
481 # {{{ Use hard limits, except for a smaller stack and no core dumps
484 limit core 0 # important for a live-cd-system
488 # {{{ completion stuff
490 # Where to look for autoloaded function definitions
491 if [ -d /etc/zsh/completion.d ] ; then
492 local comp=/etc/zsh/completion.d
493 for func in $comp/*(N-.:t); . ${comp}/${func}
496 # called later (via is4 && grmlcomp)
497 # notice: use 'zstyle' for getting current settings
498 # press ^Xh (control-x h) for getting tags in context; ^X? (control-x ?) to run complete_debug with trace output
501 zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer
502 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~' # don't complete backup files as executables
503 zstyle ':completion:*:correct:*' insert-unambiguous true # start menu completion only if it could find no unambiguous initial string
504 zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' #
505 zstyle ':completion:*:correct:*' original true #
506 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} # activate color-completion(!)
507 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' # format on completion
508 zstyle ':completion:*:*:cd:*:directory-stack' menu yes select # complete 'cd -<tab>' with menu
509 zstyle ':completion:*:expand:*' tag-order all-expansions # insert all expansions for expand completer
510 zstyle ':completion:*:history-words' list false #
511 zstyle ':completion:*:history-words' menu yes # activate menu
512 zstyle ':completion:*:history-words' remove-all-dups yes # ignore duplicate entries
513 zstyle ':completion:*:history-words' stop yes #
514 zstyle ':completion:*:*:linda:*' file-patterns '*.deb' # complete debian packages for command 'linda'
515 zstyle ':completion:*:*:lintian:*' file-patterns '*.deb' # complete debian packages for command 'lintian'
516 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # match uppercase from lowercase
517 zstyle ':completion:*:matches' group 'yes' # separate matches into groups
518 if [[ -z "$NOMENU" ]] ; then
519 zstyle ':completion:*' menu select=5 # if there are more than 5 options allow selecting from a menu
521 setopt no_auto_menu # don't use any menus at all
523 zstyle ':completion:*:messages' format '%d' #
524 zstyle ':completion:*:options' auto-description '%d' #
525 zstyle ':completion:*:options' description 'yes' # describe options in full
526 zstyle ':completion:*:processes' command 'ps -au$USER' # on processes completion complete all user processes
527 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters # offer indexes before parameters in subscripts
528 zstyle ':completion:*' verbose true # provide verbose completion information
529 zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d' # set format for warnings
530 zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)' # define files to ignore for zcompile
531 zstyle ':completion:correct:' prompt 'correct to: %e' #
532 zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*' # Ignore completion functions for commands you don't have:
534 # complete manual by their section
535 zstyle ':completion:*:manuals' separate-sections true
536 zstyle ':completion:*:man:*' menu yes select
539 # run rehash on completion so new installed program are found automatically:
541 (( CURRENT == 1 )) && rehash
542 return 1 # Because we didn't really complete anything
544 # some people don't like the automatic correction - so run 'NOCOR=1 zsh' to deactivate it
545 if [[ -n "$NOCOR" ]] ; then
546 zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete
547 setopt nocorrect # do not try to correct the spelling if possible
549 # zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _correct _approximate
550 setopt correct # try to correct the spelling if possible
551 zstyle -e ':completion:*' completer '
552 if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]; then
553 _last_try="$HISTNO$BUFFER$CURSOR"
554 reply=(_complete _match _prefix)
556 if [[ $words[1] = (rm|mv) ]]; then
559 reply=(_oldlist _expand _force_rehash _complete _correct _approximate)
563 # zstyle ':completion:*' completer _complete _correct _approximate
564 # zstyle ':completion:*' expand prefix suffix
566 # command for process lists, the local web server details and host completion
567 hosts=(`hostname` grml.org)
568 zstyle '*' hosts $hosts
569 zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
572 [ -d $ZSHDIR/cache ] && zstyle ':completion:*' use-cache yes && \
573 zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
575 # use ~/.ssh/known_hosts for completion [does not work with hashing of new ssh versions anymore]
576 if [ -f "$HOME/.ssh/known_hosts" ] ; then
577 hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*})
578 zstyle ':completion:*:hosts' hosts $hosts
581 # use generic completion system for programs not yet defined:
582 compdef _gnu_generic tail head feh cp mv gpg df stow uname ipacsum fetchipac
584 # see upgrade function in this file
585 compdef _hosts upgrade
591 # people should use 'grml-x'!
593 if [ -e /etc/X11/xorg.conf ] ; then
594 [ -x /usr/bin/startx ] && /usr/bin/startx || /usr/X11R6/bin/startx
596 echo "Please use the script \"grml-x\" for starting the X Window System
597 because there does not exist /etc/X11/xorg.conf yet.
598 If you want to use startx anyway please call \"/usr/bin/startx\"."
604 if [ -e /etc/X11/xorg.conf ] ; then
605 [ -x /usr/bin/xinit ] && /usr/bin/xinit || /usr/X11R6/bin/xinit
607 echo "Please use the script \"grml-x\" for starting the X Window System.
608 because there does not exist /etc/X11/xorg.conf yet.
609 If you want to use xinit anyway please call \"/usr/bin/xinit\"."
614 if [ -x /usr/sbin/915resolution ] ; then
615 alias 855resolution='echo -e "Please use 915resolution as resolution modify tool for Intel graphic chipset."; return -1'
618 alias grml-version='cat /etc/grml_version'
620 if [ -x /usr/sbin/rebuildfstab ] ; then
621 local fstabuser=$(getent passwd 1000 | cut -d: -f1)
622 alias grml-rebuildfstab="rebuildfstab -v -r -u $fstabuser -g $fstabuser"
627 # {{{ now run the functions
629 is4 && isgrml && grmlstuff
634 [ -r /etc/zsh/keephack ] && is4 && source /etc/zsh/keephack
637 # {{{ wonderful idea of using "e" glob qualifier by Peter Stephenson
638 # You use it as follows:
639 # $ NTREF=/reference/file
641 # This lists all the files in the current directory newer than the reference file.
642 # You can also specify the reference file inline; note quotes:
643 # $ ls -l *(e:'nt ~/.zshenv':)
648 [[ $REPLY -nt $NTREF ]]
652 # shell functions {{{
653 setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } # csh compatibility
654 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
655 manzsh() { /usr/bin/man zshall | vim -c "se ft=man| se hlsearch" +/"$1" - ; }
656 # manzsh() { man zshall | $MYLESS -p $1 ; }
657 # manzsh() { /usr/bin/man zshall | most +/"$1" ; }
659 # use "dchange <package-name>" to view Debian's changelog of the package:
660 dchange() { most /usr/share/doc/${1}/changelog.Debian.gz ; }
661 _dchange() { _files -W /usr/share/doc -/ }
662 compdef _dchange dchange
664 # use "uchange <package-name>" to view upstream's changelog of the package:
665 uchange() { most /usr/share/doc/${1}/changelog.gz ; }
666 _uchange() { _files -W /usr/share/doc -/ }
667 compdef _uchange uchange
669 # edit alias via zle:
671 [ -z "$1" ] && { echo "Usage: edalias <alias_to_edit>" ; return 1 } || vared aliases'[$1]' ;
673 compdef _aliases edalias
675 # edit function via zle:
677 [ -z "$1" ] && { echo "Usage: edfun <function_to_edit>" ; return 1 } || zed -f "$1" ;
679 compdef _functions edfun
681 # use it e.g. via 'Restart apache2'
682 if [ -d /etc/init.d ] ; then
683 for i in Start Restart Stop Reload ; do
684 eval "$i() { $SUDO /etc/init.d/\$1 ${i:l} $2 ; }"
686 # now the completion for this:
687 compctl -g "$(echo /etc/init.d/*(:t))" Start Restart Stop Reload
691 # source another config file if present {{{
692 if [ -r /etc/zsh/zshrc.local ]; then
693 source /etc/zsh/zshrc.local
697 # "persistent history" {{{
698 # just write important commands you always need to ~/.important_commands
699 if [ -r ~/.important_commands ] ; then
700 fc -R ~/.important_commands
704 ## END OF FILE #################################################################
705 # vim:foldmethod=marker