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: Sam Okt 21 16:20:30 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 [[ $ZSH_VERSION == 4.* ]] && return 0
24 [[ $ZSH_VERSION == 4.<2->* ]] && return 0
30 [ -f /etc/grml_version ] && return 0
35 [ -f /etc/grml_cd ] && return 0
39 # check for user, if not running as root set $SUDO to sudo
40 (( EUID != 0 )) && SUDO='sudo' || SUDO=''
42 # change directory to home on first invocation of zsh
43 # important for rungetty -> autologin
44 # Thanks go to Bart Schaefer!
45 isgrml && checkhome() {
46 if [[ -z "$ALREADY_DID_CD_HOME" ]]; then
47 export ALREADY_DID_CD_HOME=$HOME
53 # {{{ set some variables
54 export EDITOR=${EDITOR:-vim}
55 export SHELL=${SHELL:-/bin/zsh}
56 export MAIL=${MAIL:-/var/mail/$USER}
57 [[ -f ~/.terminfo/m/mostlike ]] && MYLESS='LESS=C TERMINFO=~/.terminfo TERM=mostlike less' || MYLESS='less'
58 [[ -x /usr/bin/dircolors ]] && eval `dircolors -b`
60 # Search path for the cd comman
63 # Support our own site-functions
64 [ -d /etc/zsh/site-functions ] && export FPATH=/etc/zsh/site-functions:$FPATH
66 # automatically remove duplicates from these arrays
67 typeset -U path cdpath fpath manpath
71 if [[ "$TERM" != emacs ]]; then
72 [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
73 [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
74 [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
75 [[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
76 [[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
77 [[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
78 [[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
79 [[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
80 [[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
81 [[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
82 [[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
83 [[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char
85 [[ "$terminfo[kcuu1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
86 [[ "$terminfo[kcud1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
87 [[ "$terminfo[kcuf1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
88 [[ "$terminfo[kcub1]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
89 [[ "$terminfo[khome]" == "
\eO"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
90 [[ "$terminfo[kend]" == "
\eO"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
91 [[ "$terminfo[khome]" == "
\eO"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
92 [[ "$terminfo[kend]" == "
\eO"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
95 ## keybindings (run 'bindkeys' for details, more details via man zshzle)
96 # use emacs style per default
101 #if [[ "$TERM" == screen ]]; then
102 bindkey '\e[1~' beginning-of-line # home
103 bindkey '\e[4~' end-of-line # end
104 bindkey "^[[A" up-line-or-search # cursor up
105 bindkey "^[[B" down-line-or-search # <ESC>-
106 bindkey '^x' history-beginning-search-backward # alternative ways of searching the shell history
107 # bindkey -s '^L' "|less\n" # ctrl-L pipes to less
108 # bindkey -s '^B' " &\n" # ctrl-B runs it in the background
109 # if terminal type is set to 'rxvt':
110 bindkey '\e[7~' beginning-of-line # home
111 bindkey '\e[8~' end-of-line # end
114 # bindkey '\eq' push-line-or-edit
118 autoload -U zmv # who needs mmv or rename?
119 autoload history-search-end
121 # we don't want to quote/espace URLs on our own...
122 # avoid 'url-quote-magic: function definition file not found' on some older boxes
123 if [ -f "/usr/share/zsh/$ZSH_VERSION/functions/Zle/url-quote-magic" ] ; then
124 autoload -U url-quote-magic && zle -N self-insert url-quote-magic
126 print 'Notice: no url-quote-magic available :('
129 alias run-help >&/dev/null && unalias run-help
130 autoload run-help # use via 'esc-h'
133 is42 && if autoload -U compinit && [ -f "/usr/share/zsh/$ZSH_VERSION/functions/Completion/compinit" ] ; then
136 print 'Notice: no compinit available :('
140 is4 && autoload -U zed # use ZLE editor to edit a file or function
143 for mod in complist deltochar mathfunc ; do
144 zmodload -i zsh/${mod}
146 # autoload zsh modules when they are referenced
148 for opt mod in a stat \
152 zmodload -${opt} zsh/${mod} ${mod}
156 is4 && autoload -U insert-files && \
157 zle -N insert-files && \
158 bindkey "^Xf" insert-files # C-x-f
160 bindkey ' ' magic-space # also do history expansion on space
161 bindkey '\ei' menu-complete # menu completion via esc-i
163 # press esc-e for editing command line in $EDITOR or $VISUAL
164 is4 && autoload -U edit-command-line && \
165 zle -N edit-command-line && \
166 bindkey '\ee' edit-command-line
168 ## menu selection: pick item but stay in the menu (press esc-return)
169 is4 && bindkey -M menuselect '\e^M' accept-and-menu-complete
171 # press "ctrl-e d" to insert the actual date in the form yyyy-mm-dd
172 _bkdate() { BUFFER="$BUFFER$(date '+%F')"; CURSOR=$#BUFFER; }
173 bindkey '\C-ed' _bkdate
176 # press esc-m for inserting last typed word again (thanks to caphuso!)
177 insert-last-typed-word() { zle insert-last-word -- 0 -1 }; \
178 zle -N insert-last-typed-word; bindkey "\em" insert-last-typed-word
180 # set command prediction from history, see 'man 1 zshcontrib'
181 # is4 && autoload -U predict-on && \
182 # zle -N predict-on && \
183 # zle -N predict-off && \
184 # bindkey "^X^Z" predict-on && \
185 # bindkey "^Z" predict-off
187 # put job into foreground via ctrl-z:
188 bindkey -s '^z' "fg\n"
190 # press ctrl-q to quote line:
192 # zle beginning-of-line
194 # # RBUFFER="'$RBUFFER'"
195 # RBUFFER=${(q)RBUFFER}
198 # zle -N mquote && bindkey '^q' mquote
200 # run command line as user root via sudo:
201 _sudo-command-line() {
202 [[ $BUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER"
204 zle -N sudo-command-line _sudo-command-line
205 bindkey "^Os" sudo-command-line
208 # {{{ set some important options
212 setopt append_history # append history list to the history file (important for multiple parallel zsh sessions!)
213 is4 && setopt SHARE_HISTORY # import new commands from the history file also in other zsh-session
214 setopt extended_history # save each command's beginning timestamp and the duration to the history file
215 is4 && setopt histignorealldups # If a new command line being added to the history
216 # list duplicates an older one, the older command is removed from the list
217 setopt histignorespace # remove command lines from the history list when
218 # the first character on the line is a space
219 # setopt histallowclobber # add `|' to output redirections in the history
220 # setopt NO_clobber # warning if file exists ('cat /dev/null > ~/.zshrc')
221 setopt auto_cd # if a command is issued that can't be executed as a normal command,
222 # and the command is the name of a directory, perform the cd command to that directory
223 setopt extended_glob # in order to use #, ~ and ^ for filename generation
224 # grep word *~(*.gz|*.bz|*.bz2|*.zip|*.Z) ->
225 # -> searches for word not in compressed files
226 # don't forget to quote '^', '~' and '#'!
227 setopt notify # report the status of backgrounds jobs immediately
228 setopt hash_list_all # Whenever a command completion is attempted, make sure \
229 # the entire command path is hashed first.
230 setopt completeinword # not just at the end
231 # setopt nocheckjobs # don't warn me about bg processes when exiting
232 setopt nohup # and don't kill them, either
233 # setopt printexitvalue # alert me if something failed
234 # setopt dvorak # with spelling correction, assume dvorak kb
235 setopt auto_pushd # make cd push the old directory onto the directory stack.
236 setopt nonomatch # try to avoid the 'zsh: no matches found...'
237 setopt nobeep # avoid "beep"ing
239 MAILCHECK=30 # mailchecks
240 REPORTTIME=5 # report about cpu-/system-/user-time of command if running longer than 5 secondes
241 watch=(notme root) # watch for everyone but me and root
243 # define word separators (for stuff like backward-word, forward-word, backward-kill-word,..)
244 # WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' # the default
246 # WORDCHARS='*?_[]~=&;!#$%^(){}'
247 # WORDCHARS='${WORDCHARS:s@/@}'
249 # only slash should be considered as a word separator:
250 slash-backward-kill-word() {
251 local WORDCHARS="${WORDCHARS:s@/@}"
253 zle backward-kill-word
255 zle -N slash-backward-kill-word
256 bindkey '
\ev' slash-backward-kill-word # press esc-v to delete a word until its last '/' (not the same as ctrl-w!)
260 export ZSHDIR=$HOME/.zsh
261 HISTFILE=$HOME/.zsh_history
262 isgrmlcd && HISTSIZE=500 || HISTSIZE=5000
263 isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history
266 # {{{ display battery status on right side of prompt via running 'BATTERY=1 zsh'
267 if [ -n "$BATTERY" ] ; then
268 if [ -x =acpi ] ; then
269 PERCENT="${(C)${(s| |)$(acpi 2>/dev/null)}[4]}"
270 [ -z "$PERCENT" ] && PERCENT='acpi not present'
271 if [ "${PERCENT%%%}" -lt 20 ] ; then
272 PERCENT="warning: ${PERCENT}%"
279 if [ -f "/usr/share/zsh/$ZSH_VERSION/functions/Prompts/promptinit" ] ; then
280 autoload promptinit && promptinit # people should be able to use their favourite prompt
282 print 'Notice: no prompiinit available :('
284 # precmd() => a function which is executed just before each prompt
285 # precmd () { setopt promptsubst; [[ -o interactive ]] && jobs -l;
286 # run 'NOPRECMD=1 zsh' to disable the precmd + preexec commands
287 is4 && ! [[ -n "$NOPRECMD" ]] && precmd () {
288 if [ -n "$BATTERY" ] ; then
289 RPROMPT="%(?..:()% ${PERCENT}${SCREENTITLE}"
291 RPROMPT="%(?..:()% ${SCREENTITLE}"
293 # adjust title of xterm
294 # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
295 case $TERM in (xterm*|rxvt)
296 print -Pn "\e]0;%n@%m: %~\a"
301 # chpwd () => a function which is executed whenever the directory is changed
303 # preexec() => a function running before every command
304 is4 && ! [[ -n "$NOPRECMD" ]] && preexec () {
305 # set screen window title if running in a screen
306 # get the name of the program currently running and hostname of local machine
307 local HOSTNAME=$(hostname)
308 if [[ "$HOSTNAME" != grml ]] ; then
311 if [[ "$TERM" == screen* ]]; then
312 # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} # dont't use hostname
313 local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
314 echo -ne "\ek$CMD\e\\"
316 # set the screen title to "zsh" when sitting at the command prompt:
317 if [[ "$TERM" == screen* ]]; then
318 SCREENTITLE=$'%{\ekzsh\e\\%}'
322 # adjust title of xterm
323 case $TERM in (xterm*|rxvt)
324 print -Pn "\e]0;%n@%m: $1\a"
329 EXITCODE="%(?..%?%1v )"
330 local BLUE="%{
\e[1;34m%}"
331 local RED="%{
\e[1;31m%}"
332 local GREEN="%{
\e[1;32m%}"
333 local CYAN="%{
\e[1;36m%}"
334 local WHITE="%{
\e[1;37m%}"
335 local NO_COLOUR="%{
\e[0m%}"
336 PS2='`%_> ' # secondary prompt, printed when the shell needs more information to complete a command.
337 PS3='?# ' # selection prompt used within a select loop.
338 PS4='+%N:%i:%_> ' # the execution trace prompt (setopt xtrace). default: '+%N:%i>'
340 # set variable debian_chroot if running in a chroot with /etc/debian_chroot
341 if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
342 debian_chroot=$(cat /etc/debian_chroot)
345 # don't use colors on dumb terminals (like emacs):
346 if [[ "$TERM" == dumb ]] ; then
347 PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< %# "
349 # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended prompt
350 # set variable identifying the chroot you work in (used in the prompt below)
351 if [[ -n "$GRMLPROMPT" ]]; then
352 PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
353 ${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# "
355 if (( EUID != 0 )); then
356 PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# " # primary prompt string
358 PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< %# " # primary prompt string
363 # if we are inside a grml-chroot set a specific prompt theme
364 if [ -n "$GRML_CHROOT" ] ; then
365 PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "
369 # {{{ 'hash' some often used directories
370 hash -d deb=/var/cache/apt/archives
371 hash -d doc=/usr/share/doc
372 hash -d linux=/lib/modules/$(command uname -r)/build/
374 hash -d slog=/var/log/syslog
376 hash -d templ=/usr/share/doc/grml-templates
377 hash -d tt=/usr/share/doc/texttools-doc
382 if [ $UID = 0 ] ; then
383 [ -r /etc/grml/screenrc ] && alias screen='/usr/bin/screen -c /etc/grml/screenrc'
384 elif [ -r $HOME/.screenrc ] ; then
385 alias screen="/usr/bin/screen -c $HOME/.screenrc"
387 [ -r /etc/grml/screenrc_grml ] && alias screen='/usr/bin/screen -c /etc/grml/screenrc_grml'
390 if ls --help 2>/dev/null |grep -- --color= >/dev/null && [ "$TERM" != dumb ] ; then
391 alias ls='ls -b -CF --color=auto' # do we have GNU ls with color-support?
392 alias la='ls -la --color=auto'
393 alias ll='ls -l --color=auto'
394 alias lh='ls -hAl --color=auto'
395 alias l='ls -lF --color=auto'
404 alias cp='nocorrect cp' # no spelling correction on cp
405 alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
406 alias mv='nocorrect mv' # no spelling correction on mv
407 alias rm='nocorrect rm' # no spelling correction on rm
412 alias swspeak="setopt singlelinezle ; unsetopt prompt_cr ; export PS1='%m%# ' ; speechd-up" # set up software synth.
414 # truecrypt; use e.g. via 'truec /dev/ice' /mnt/ice' or 'truec -i'
415 if [ -x /usr/sbin/truecrypt ] ; then
416 alias truec='truecrypt --mount-options "rw,sync,dirsync,users,uid=1000,gid=users,umask=077" '
419 zsh-help(){print "$bg[white]$fg[black]
420 zsh-help - hints for use of zsh on grml
421 =======================================$reset_color
423 Main configuration of zsh happens in /etc/zsh/zshrc (global)
424 and /etc/skel/.zshrc which is copied to \$HOME/.zshrc once.
425 The files are part of the package grml-etc, if you want to
426 use them on a non-grml-system just get the tar.gz from
427 http://grml.org/repos/
429 If you want to stay in sync with zsh configuration of grml
430 run 'ln -sf /etc/skel/.zshrc \$HOME/.zshrc' and configure
431 your own stuff in \$HOME/.zshrc.local. System wide configuration
432 without touching configuration files of grml can take place
433 in /etc/zsh/zshrc.local.
435 If you want to use the configuration of user grml also when
436 running as user root just run 'zshskel' which will source
437 the file /etc/skel/.zshrc.
439 For information regarding zsh start at http://grml.org/zsh/
441 Take a look at grml's zsh refcard:
442 % xpdf =(zcat /usr/share/doc/grml-docs/zsh/grml-zsh-refcard.pdf.gz)
444 Check out the main zsh refcard:
445 % $BROWSER http://www.bash2zsh.com/zsh_refcard/refcard.pdf
447 And of course visit the zsh-lovers:
450 You can adjust some options through environment variables when
451 invoking zsh without having to edit configuration files.
452 Basically meant for bash users who are not used to the power of
455 \"NOCOR=1 zsh\" => deactivate automatic correction
456 \"NOMENU=1 zsh\" => do not use menu completion (note: use strg-d for completion instead!)
457 \"NOPRECMD=1 zsh\" => disable the precmd + preexec commands (set GNU screen title)
458 \"BATTERY=1 zsh\" => activate battery status (via acpi) on right side of prompt
460 Please report wishes + bugs to the grml-team: http://grml.org/bugs/
461 Enjoy your grml system with the zsh!$reset_color"
465 if [ -r /etc/debian_version ] ; then
466 alias acs="apt-cache search"
467 alias acsh="apt-cache show"
468 alias adg="$SUDO apt-get dist-upgrade"
469 alias agi="$SUDO apt-get install"
470 alias ag="$SUDO apt-get upgrade"
471 alias au="$SUDO apt-get update"
472 alias dbp="dpkg-buildpackage"
473 alias ge="grep-excuses"
475 isgrmlcd && alias su="sudo su" # change to user root
476 alias tlog="tail -f /var/log/syslog" # take a look at the syslog
477 alias zshskel="source /etc/skel/.zshrc" # source skeleton zshrc
480 # if cdrecord is a symlink (to wodim) or isn't present at all warn:
481 if [ -L /usr/bin/cdrecord -o ! -x =cdrecord ] ; then
482 if [ -x =wodim ] ; then
483 alias cdrecord="echo 'cdrecord is not provided under its original name by Debian anymore.
484 See #377109 in the BTS of Debian for more details.
486 Please use the wodim binary instead' ; return 1"
492 # {{{ Use hard limits, except for a smaller stack and no core dumps
495 limit core 0 # important for a live-cd-system
499 # {{{ completion stuff
501 # Where to look for autoloaded function definitions
502 if [ -d /etc/zsh/completion.d ] ; then
503 local comp=/etc/zsh/completion.d
504 for func in $comp/*(N-.:t); . ${comp}/${func}
507 # called later (via is4 && grmlcomp)
508 # notice: use 'zstyle' for getting current settings
509 # press ^Xh (control-x h) for getting tags in context; ^X? (control-x ?) to run complete_debug with trace output
512 zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer
513 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~' # don't complete backup files as executables
514 zstyle ':completion:*:correct:*' insert-unambiguous true # start menu completion only if it could find no unambiguous initial string
515 zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' #
516 zstyle ':completion:*:correct:*' original true #
517 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} # activate color-completion(!)
518 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' # format on completion
519 zstyle ':completion:*:*:cd:*:directory-stack' menu yes select # complete 'cd -<tab>' with menu
520 zstyle ':completion:*:expand:*' tag-order all-expansions # insert all expansions for expand completer
521 zstyle ':completion:*:history-words' list false #
522 zstyle ':completion:*:history-words' menu yes # activate menu
523 zstyle ':completion:*:history-words' remove-all-dups yes # ignore duplicate entries
524 zstyle ':completion:*:history-words' stop yes #
525 zstyle ':completion:*:*:linda:*' file-patterns '*.deb' # complete debian packages for command 'linda'
526 zstyle ':completion:*:*:lintian:*' file-patterns '*.deb' # complete debian packages for command 'lintian'
527 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # match uppercase from lowercase
528 zstyle ':completion:*:matches' group 'yes' # separate matches into groups
529 zstyle ':completion:*' group-name ''
530 if [[ -z "$NOMENU" ]] ; then
531 zstyle ':completion:*' menu select=5 # if there are more than 5 options allow selecting from a menu
533 setopt no_auto_menu # don't use any menus at all
535 zstyle ':completion:*:messages' format '%d' #
536 zstyle ':completion:*:options' auto-description '%d' #
537 zstyle ':completion:*:options' description 'yes' # describe options in full
538 zstyle ':completion:*:processes' command 'ps -au$USER' # on processes completion complete all user processes
539 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters # offer indexes before parameters in subscripts
540 zstyle ':completion:*' verbose true # provide verbose completion information
541 zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d' # set format for warnings
542 zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)' # define files to ignore for zcompile
543 zstyle ':completion:correct:' prompt 'correct to: %e' #
544 zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*' # Ignore completion functions for commands you don't have:
546 # complete manual by their section
547 zstyle ':completion:*:manuals' separate-sections true
548 zstyle ':completion:*:manuals.*' insert-sections true
549 zstyle ':completion:*:man:*' menu yes select
552 # run rehash on completion so new installed program are found automatically:
554 (( CURRENT == 1 )) && rehash
555 return 1 # Because we didn't really complete anything
557 # some people don't like the automatic correction - so run 'NOCOR=1 zsh' to deactivate it
558 if [[ -n "$NOCOR" ]] ; then
559 zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete
560 setopt nocorrect # do not try to correct the spelling if possible
562 # zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _correct _approximate
563 setopt correct # try to correct the spelling if possible
564 zstyle -e ':completion:*' completer '
565 if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]]; then
566 _last_try="$HISTNO$BUFFER$CURSOR"
567 reply=(_complete _match _prefix)
569 if [[ $words[1] = (rm|mv) ]]; then
572 reply=(_oldlist _expand _force_rehash _complete _correct _approximate)
576 # zstyle ':completion:*' completer _complete _correct _approximate
577 # zstyle ':completion:*' expand prefix suffix
579 # automatic rehash? Credits go to Frank Terbeck
580 # function my_accept () {
582 # [[ -z ${BUFFER} ]] && zle accept-line && return
583 # buf=( ${(z)BUFFER} )
584 # [[ -z ${commands[${buf[1]}]} ]] && rehash
588 # bindkey "^M" my_accept
590 # command for process lists, the local web server details and host completion
591 hosts=(`hostname` grml.org)
592 zstyle '*' hosts $hosts
593 zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
596 [ -d $ZSHDIR/cache ] && zstyle ':completion:*' use-cache yes && \
597 zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
599 # use ~/.ssh/known_hosts for completion [does not work with hashing of new ssh versions anymore]
600 if [ -f "$HOME/.ssh/known_hosts" ] ; then
601 hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*})
602 zstyle ':completion:*:hosts' hosts $hosts
605 # use generic completion system for programs not yet defined:
606 compdef _gnu_generic tail head feh cp mv gpg df stow uname ipacsum fetchipac
608 # see upgrade function in this file
609 compdef _hosts upgrade
615 # people should use 'grml-x'!
617 if [ -e /etc/X11/xorg.conf ] ; then
618 [ -x /usr/bin/startx ] && /usr/bin/startx || /usr/X11R6/bin/startx
620 echo "Please use the script \"grml-x\" for starting the X Window System
621 because there does not exist /etc/X11/xorg.conf yet.
622 If you want to use startx anyway please call \"/usr/bin/startx\"."
628 if [ -e /etc/X11/xorg.conf ] ; then
629 [ -x /usr/bin/xinit ] && /usr/bin/xinit || /usr/X11R6/bin/xinit
631 echo "Please use the script \"grml-x\" for starting the X Window System.
632 because there does not exist /etc/X11/xorg.conf yet.
633 If you want to use xinit anyway please call \"/usr/bin/xinit\"."
638 if [ -x /usr/sbin/915resolution ] ; then
639 alias 855resolution='echo -e "Please use 915resolution as resolution modify tool for Intel graphic chipset."; return -1'
642 alias grml-version='cat /etc/grml_version'
644 if [ -x /usr/sbin/rebuildfstab ] ; then
645 local fstabuser=$(getent passwd 1000 | cut -d: -f1)
646 alias grml-rebuildfstab="rebuildfstab -v -r -u $fstabuser -g $fstabuser"
651 # {{{ now run the functions
653 is4 && isgrml && grmlstuff
658 [ -r /etc/zsh/keephack ] && is4 && source /etc/zsh/keephack
661 # {{{ wonderful idea of using "e" glob qualifier by Peter Stephenson
662 # You use it as follows:
663 # $ NTREF=/reference/file
665 # This lists all the files in the current directory newer than the reference file.
666 # You can also specify the reference file inline; note quotes:
667 # $ ls -l *(e:'nt ~/.zshenv':)
672 [[ $REPLY -nt $NTREF ]]
676 # shell functions {{{
677 setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" } # csh compatibility
678 freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }
679 manzsh() { /usr/bin/man zshall | vim -c "se ft=man| se hlsearch" +/"$1" - ; }
680 # manzsh() { man zshall | $MYLESS -p $1 ; }
681 # manzsh() { /usr/bin/man zshall | most +/"$1" ; }
683 # use "dchange <package-name>" to view Debian's changelog of the package:
685 if [ -r /usr/share/doc/${1}/changelog.Debian.gz ] ; then
686 most /usr/share/doc/${1}/changelog.Debian.gz
688 if [ -r /usr/share/doc/${1}/changelog.gz ] ; then
689 most /usr/share/doc/${1}/changelog.gz
691 echo "No changelog for package $1 found, sorry."
696 _dchange() { _files -W /usr/share/doc -/ }
697 compdef _dchange dchange
699 # use "uchange <package-name>" to view upstream's changelog of the package:
701 if [ -r /usr/share/doc/${1}/changelog.gz ] ; then
702 most /usr/share/doc/${1}/changelog.gz
704 echo "No changelog for package $1 found, sorry."
708 _uchange() { _files -W /usr/share/doc -/ }
709 compdef _uchange uchange
711 # edit alias via zle:
713 [ -z "$1" ] && { echo "Usage: edalias <alias_to_edit>" ; return 1 } || vared aliases'[$1]' ;
715 compdef _aliases edalias
717 # edit function via zle:
719 [ -z "$1" ] && { echo "Usage: edfun <function_to_edit>" ; return 1 } || zed -f "$1" ;
721 compdef _functions edfun
723 # use it e.g. via 'Restart apache2'
724 if [ -d /etc/init.d ] ; then
725 for i in Start Restart Stop Reload ; do
726 eval "$i() { $SUDO /etc/init.d/\$1 ${i:l} $2 ; }"
728 # now the completion for this:
729 compctl -g "$(echo /etc/init.d/*(:t))" Start Restart Stop Reload
733 # source another config file if present {{{
734 if [ -r /etc/zsh/zshrc.local ]; then
735 source /etc/zsh/zshrc.local
739 # "persistent history" {{{
740 # just write important commands you always need to ~/.important_commands
741 if [ -r ~/.important_commands ] ; then
742 fc -R ~/.important_commands
746 ## END OF FILE #################################################################
747 # vim:foldmethod=marker