1 # Ceci est un zshrc proposé par PEB.
2 # Il est issu d'un zshrc pompé allègrement chez une ancienne nounou
3 # qui l'avait elle-même pompé chez une ancienne nounou, qui l'avait...
6 # La conf est stockée dans le dossier .zsh, en plusieurs parties, base, extra, et local.
7 # local est la conf que vous devriez regarder et éventuellement changer. Cherchez les
8 # #~# dans les fichiers, il y aura des mentions de quoi changer.
10 # Ce fichier sert à orchestrer tout le bordel.
12 # Pour faire marcher ce .zshrc, soit vous copiez .zshrc et .zsh dans votre home, soit
13 # vous faites des liens symboliques vers l'endroit de votre home où ils se trouvent.
15 ###############################################################################
16 # This file is sourced only for interactive shells. It
17 # should contain commands to set up aliases, functions,
18 # options, key bindings, etc.
20 # Global Order: zshenv, zprofile, zshrc, zlogin
21 ################################################################################
26 for file in $ZSHDIR/rc/base/*; do
31 # zmv is a zsh massive renaming tool
33 # zmv [OPTIONS] oldpattern newpattern
34 # where oldpattern contains parenthesis surrounding patterns which will
35 # be replaced in turn by $1, $2, ... in newpattern. For example,
36 # zmv '(*).lis' '$1.txt'
37 # renames 'foo.lis' to 'foo.txt', 'my.old.stuff.lis' to 'my.old.stuff.txt',
38 # and so on. Something simpler (for basic commands) is the -W option:
39 # zmv -W '*.lis' '*.txt'
40 # This does the same thing as the first command, but with automatic conversion
41 # of the wildcards into the appropriate syntax. If you combine this with
42 # noglob, you don't even need to quote the arguments. For example,
43 # alias mmv='noglob zmv -W'
44 # mmv *.c.orig orig/*.c
47 # I'm not pretty sure of what it does. :D
48 zrcautoload history-search-end
50 #m# k ESC-h Call \kbd{run-help} for the 1st word on the command line
51 alias run-help >&/dev/null && unalias run-help
52 for rh in run-help{,-git,-svk,-svn}; do
56 # loads completion system
57 if zrcautoload compinit ; then
58 compinit || print 'Notice: no compinit available :('
60 # creates fake functions
61 print 'Notice: no compinit available :('
66 # zed - /usr/share/zsh/functions/Misc/zed
68 # No other shell could do this.
69 # Edit small files with the command line editor.
70 # Use ^X^W to save, ^C to abort.
71 # Option -f: edit shell functions. (Also if called as fned.)
74 # Loads .so modules in /usr/lib/i386-linux-gnu/zsh/${ZSHVERSION}/zsh/
75 for mod in complist deltochar mathfunc ; do
76 zmodload -i zsh/${mod} 2>/dev/null || print "Notice: no ${mod} available :("
79 # autoload zsh modules when they are referenced
80 # uses bidimensionnal array to give option to zmodload
87 while (( ${#tmpargs} > 0 )) ; do
88 zmodload -${tmpargs[1]} zsh/${tmpargs[2]} ${tmpargs[2]}
94 # I wasn't able to find a good .zsh/rc/* file for this
95 DIRSTACKSIZE=${DIRSTACKSIZE:-20}
96 DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs}
98 if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
99 dirstack=( ${(f)"$(< $DIRSTACKFILE)"} )
100 # "cd -" won't work after login by just setting $OLDPWD, so
101 [[ -d $dirstack[0] ]] && cd $dirstack[0] && cd $OLDPWD
106 my_stack=( ${PWD} ${dirstack} )
107 builtin print -l ${(u)my_stack} >! ${DIRSTACKFILE}
110 # In order to set prompt, and because we love comfort
111 # These files are not mandatory, but removing them
112 # would break the PS1 prompt.
113 for file in $ZSHDIR/rc/extra/*; do
118 if zrcautoload promptinit && promptinit 2>/dev/null ; then
119 promptinit # people should be able to use their favourite prompt
121 print 'Notice: no promptinit available :('
126 # make sure to use right prompt only when not running a command
127 setopt transient_rprompt
129 function ESC_print () {
130 info_print $'\ek' $'\e\\' "$@"
132 function set_title () {
133 info_print $'\e]0;' $'\a' "$@"
136 function info_print () {
137 local esc_begin esc_end
141 printf '%s' ${esc_begin}
142 for item in "$@" ; do
145 printf '%s' "${esc_end}"
148 #+--------------------------------------+
150 #+--------------------------------------+
152 # set colors for use in prompts (no longer useful, I'll trash it some day) {{{
153 if zrcautoload colors 2> /dev/null && colors 2>/dev/null ; then
155 RED="${fg_bold[red]}"
158 MAGENTA="${fg[magenta]}"
159 YELLOW="${fg[yellow]}"
161 NO_COLOUR="${reset_color}"
173 # Change vcs_info formats for the grml prompt. The 2nd format sets up
174 # $vcs_info_msg_1_ to contain "zsh: repo-name" used to set our screen title.
175 # TODO: The included vcs_info() version still uses $VCS_INFO_message_N_.
176 # That needs to be the use of $VCS_INFO_message_N_ needs to be changed
177 # to $vcs_info_msg_N_ as soon as we use the included version.
178 if [[ "$TERM" == dumb ]] ; then
179 zstyle ':vcs_info:*' actionformats "(%s)-[%r/%b|%a]" "(%s)-[%r/%b|%a]"
180 zstyle ':vcs_info:*' formats "(%s)-[%r/%b]" "(%s)-[%r/%b]"
182 # these are the same, just with a lot of colours:
183 zstyle ':vcs_info:*' actionformats "%F{magenta}(%F{no}%s%F{magenta})%F{yellow}-%F{magenta}[%F{green}%r%F{yellow}/%F{green}%b%F{yellow}|%F{red}%a%F{magenta}]%F{no}" \
185 zstyle ':vcs_info:*' formats "%F{magenta}(%F{no}%s%F{magenta})%F{yellow}-%F{magenta}[%F{green}%r%F{yellow}/%F{green}%b%F{magenta}]%F{no}" \
187 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b%F{red}:%F{yellow}%r"
190 # Built using /usr/share/zsh/functions/Prompts/prompt_adam2…
191 EXITCODE="%(?..[%?]%1v)"
193 # Set of chars used in prompt
199 # Set of colors used in prompt.
200 #~# Couleurs du prompt
201 prompt_color1='cyan' # hyphens
202 prompt_color2='green' # current directory
203 prompt_color3='yellow' # user@host
204 prompt_color4='cyan' # user input
205 prompt_color5='red' # date
207 # see man zshmisc for explanation about %B, %F, %b…
208 prompt_tbox="%B%F{$prompt_color1}${prompt_tlc}%b%F{$prompt_color1}${prompt_hyphen}"
209 prompt_bbox="%B%F{$prompt_color1}${prompt_blc}${prompt_hyphen}%b%F{$prompt_color1}"
211 # This is a cute hack. Well I like it, anyway.
212 prompt_bbox_to_mbox=$'%{\e[A\r'"%}%B%F{$prompt_color1}${prompt_mlc}%b%F{$prompt_color1}${prompt_hyphen}%{"$'\e[B%}'
214 # left and right parenthesis
215 prompt_l_paren="%B%F{black}("
216 prompt_r_paren="%B%F{black})"
218 # User : %n, host : %M
219 prompt_user_host="%b%F{$prompt_color3}%n%B%F{$prompt_color3}@%b%F{$prompt_color3}%M"
221 # line 1 is pwd, username, host, hour…
222 prompt_line_1a="$prompt_tbox$prompt_l_paren%B%F{$prompt_color5}%*$prompt_r_paren%b%F{$prompt_color1}$prompt_hyphen$prompt_l_paren%B%F{$prompt_color2}%~$prompt_r_paren%b%F{$prompt_color1}"
223 prompt_line_1b="$prompt_l_paren$prompt_user_host$prompt_r_paren%b%F{$prompt_color1}${prompt_hyphen}"
226 prompt_line_2="$prompt_bbox${prompt_hyphen}%B%F{white}"
227 prompt_char="%(!.#.>)"
228 prompt_opts=(cr subst percent)
230 # This function is called before each prompt regenation
232 setopt noxtrace localoptions extendedglob
234 # update VCS information
237 if [[ $TERM == screen* ]] ; then
238 if [[ -n ${VCS_INFO_message_1_} ]] ; then
239 ESC_print ${VCS_INFO_message_1_}
247 # Generates battery info
249 RPROMPT="${BATTERY} ${RPROMPT}"
251 # adjust title of xterm
252 # see http://www.faqs.org/docs/Linux-mini/Xterm-Title.html
253 [[ ${NOTITLE} -gt 0 ]] && return 0
256 set_title ${(%):-"%n@%m: %~"}
260 local prompt_line_1a_width=${#${(S%%)prompt_line_1a//(\%([KF1]|)\{*\}|\%[Bbkf])}}
261 local prompt_line_1b_width=${#${(S%%)prompt_line_1b//(\%([KF1]|)\{*\}|\%[Bbkf])}}
262 local prompt_vcs_width=${#${(S%%)VCS_INFO_message_0_//(\%([KF1]|)\{*\}|\%[Bbkf])}}
264 local prompt_padding_size=$(( COLUMNS - prompt_line_1a_width - prompt_line_1b_width - prompt_vcs_width - 2 ))
266 # Try to fit in long path and user@host, and vcs_info
267 if (( prompt_padding_size > 0 )); then
269 eval "prompt_padding=\${(l:${prompt_padding_size}::${prompt_hyphen}:)_empty_zz}"
270 prompt_line_1="$prompt_line_1a$prompt_padding$prompt_hyphen$VCS_INFO_message_0_%F{$prompt_color1}$prompt_hyphen$prompt_line_1b"
272 prompt_padding_size=$(( COLUMNS - prompt_line_1a_width - prompt_vcs_width - 2 ))
274 # Didn't fit; try to fit in long path and vcs_info
275 if (( prompt_padding_size > 0 )); then
277 eval "prompt_padding=\${(l:${prompt_padding_size}::${prompt_hyphen}:)_empty_zz}"
278 prompt_line_1="$prompt_line_1a$prompt_padding$prompt_hyphen$VCS_INFO_message_0_%F{$prompt_color1}$prompt_hyphen"
280 prompt_padding_size=$(( COLUMNS - prompt_line_1a_width ))
282 # Didn't fit; try to fit in just long path
283 if (( prompt_padding_size > 0 )); then
284 eval "prompt_padding=\${(l:${prompt_padding_size}::${prompt_hyphen}:)_empty_zz}"
285 prompt_line_1="$prompt_line_1a$prompt_padding"
287 # Still didn't fit; truncate
288 local prompt_pwd_size=$(( COLUMNS - 5 ))
289 prompt_line_1="$prompt_tbox$prompt_l_paren%B%F{$prompt_color2}%$prompt_pwd_size<...<%~%<<$prompt_r_paren%b%F{$prompt_color1}$prompt_hyphen"
296 PS1="$prompt_line_1$prompt_newline$prompt_line_2%B%F{red}${EXITCODE}%b%F{$prompt_color1}$prompt_hyphen%B%F{white}$prompt_char %b%f%k"
297 PS2="$prompt_line_2$prompt_bbox_to_mbox%B%F{white}%_> %b%f%k"
298 PS3="$prompt_line_2$prompt_bbox_to_mbox%B%F{white}?# %b%f%k"
300 # Text color and style for prompt
301 zle_highlight[(r)default:*]="default:fg=$prompt_color4,bold"
304 # preexec() => a function running before every command
306 # set hostname if not running on host with name 'grml'
307 if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != $(hostname) ]] ; then
310 # get the name of the program currently running and hostname of local machine
311 # set screen window title if running in a screen
312 if [[ "$TERM" == screen* ]] ; then
313 # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} # don't use hostname
314 local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
317 # adjust title of xterm
318 [[ ${NOTITLE} -gt 0 ]] && return 0
321 set_title "${(%):-"%n@%m:"}" "$1"
327 # # set variable debian_chroot if running in a chroot with /etc/debian_chroot
328 # if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
329 # debian_chroot=$(cat /etc/debian_chroot)
332 # # don't use colors on dumb terminals (like emacs):
333 # if [[ "$TERM" == dumb ]] ; then
334 # PROMPT="${debian_chroot:+($debian_chroot)}%n@%m %# "
336 # # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended prompt
337 # # set variable identifying the chroot you work in (used in the prompt below)
338 # if [[ $GRMLPROMPT -gt 0 ]] ; then
339 # PROMPT="${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D${BLUE}%n${NO_COLOUR}@%m %# "
341 # # This assembles the primary prompt string
342 # if (( EUID != 0 )); then
343 # PROMPT="%{${WHITE}%}${debian_chroot:+($debian_chroot)}%{${BLUE}%}%n%{${NO_COLOUR}%}@%m %# "
345 # PROMPT="%{${WHITE}%}${debian_chroot:+($debian_chroot)}%{${RED}%}%n%{${NO_COLOUR}%}@%m %# "
350 # if we are inside a grml-chroot set a specific prompt theme
351 # if [[ -n "$GRML_CHROOT" ]] ; then
352 # PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "
355 # {{{ 'hash' some often used directories
357 hash -d deb=/var/cache/apt/archives
358 hash -d doc=/usr/share/doc
359 hash -d linux=/lib/modules/$(command uname -r)/build/
361 hash -d slog=/var/log/syslog
363 hash -d templ=/usr/share/doc/grml-templates
364 hash -d tt=/usr/share/doc/texttools-doc
369 # I like clean prompt, so provide simple way to get that
370 check_com 0 || alias 0='return 0'
376 # called later (via grmlcomp)
377 # note: use 'zstyle' for getting current settings
378 # press ^Xh (control-x h) for getting tags in context; ^X? (control-x ?) to run complete_debug with trace output
380 # TODO: This could use some additional information
382 # allow one error for every three characters typed in approximate completer
383 zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
385 # don't complete backup files as executables
386 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)'
388 # start menu completion only if it could find no unambiguous initial string
389 zstyle ':completion:*:correct:*' insert-unambiguous true
390 zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
391 zstyle ':completion:*:correct:*' original true
393 # activate color-completion
394 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
396 # format on completion
397 zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
399 # complete 'cd -<tab>' with menu
400 zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
402 # insert all expansions for expand completer
403 zstyle ':completion:*:expand:*' tag-order all-expansions
404 zstyle ':completion:*:history-words' list false
407 zstyle ':completion:*:history-words' menu yes
409 # ignore duplicate entries
410 zstyle ':completion:*:history-words' remove-all-dups yes
411 zstyle ':completion:*:history-words' stop yes
413 # match uppercase from lowercase
414 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
416 # separate matches into groups
417 zstyle ':completion:*:matches' group 'yes'
418 zstyle ':completion:*' group-name ''
420 # if there are more than 5 options allow selecting from a menu
421 zstyle ':completion:*' menu select=5
423 zstyle ':completion:*:messages' format '%d'
424 zstyle ':completion:*:options' auto-description '%d'
426 # describe options in full
427 zstyle ':completion:*:options' description 'yes'
429 # on processes completion complete all user processes
430 zstyle ':completion:*:processes' command 'ps -au$USER'
432 # offer indexes before parameters in subscripts
433 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
435 # provide verbose completion information
436 zstyle ':completion:*' verbose true
438 # recent (as of Dec 2007) zsh versions are able to provide descriptions
439 # for commands (read: 1st word in the line) that it will list for the user
440 # to choose from. The following disables that, because it's not exactly fast.
441 zstyle ':completion:*:-command-:*:' verbose false
443 # set format for warnings
444 zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
446 # define files to ignore for zcompile
447 zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
448 zstyle ':completion:correct:' prompt 'correct to: %e'
450 # Ignore completion functions for commands you don't have:
451 zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
453 # Provide more processes in completion of programs like killall:
454 zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
456 # complete manual by their section
457 zstyle ':completion:*:manuals' separate-sections true
458 zstyle ':completion:*:manuals.*' insert-sections true
459 zstyle ':completion:*:man:*' menu yes select
461 # provide .. as a completion
462 zstyle ':completion:*' special-dirs ..
464 # run rehash on completion so new installed program are found automatically:
466 (( CURRENT == 1 )) && rehash
471 # try to be smart about when to use what completer...
473 zstyle -e ':completion:*' completer '
474 if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]] ; then
475 _last_try="$HISTNO$BUFFER$CURSOR"
476 reply=(_complete _match _ignored _prefix _files)
478 if [[ $words[1] == (rm|mv) ]] ; then
479 reply=(_complete _files)
481 reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
485 # command for process lists, the local web server details and host completion
486 zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
489 [[ -d $ZSHDIR/cache ]] && zstyle ':completion:*' use-cache yes && \
490 zstyle ':completion::complete:*' cache-path $ZSHDIR/cache/
492 # host completion /* add brackets as vim can't parse zsh's complex cmdlines 8-) {{{ */
493 [[ -r ~/.ssh/known_hosts ]] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
494 [[ -r /etc/hosts ]] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
502 zstyle ':completion:*:hosts' hosts $hosts
503 # TODO: so, why is this here?
504 # zstyle '*' hosts $hosts
506 # use generic completion system for programs not yet defined; (_gnu_generic works
507 # with commands that provide a --help option with "standard" gnu-like output.)
508 for compcom in cp deborphan df feh fetchipac head hnb ipacsum mv \
509 pal stow tail uname ; do
510 [[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
513 # see upgrade function in this file
514 compdef _hosts upgrade
518 # people should use 'grml-x'!
520 if [[ -e /etc/X11/xorg.conf ]] ; then
521 [[ -x /usr/bin/startx ]] && /usr/bin/startx "$@" || /usr/X11R6/bin/startx "$@"
523 echo "Please use the script \"grml-x\" for starting the X Window System
524 because there does not exist /etc/X11/xorg.conf yet.
525 If you want to use startx anyway please call \"/usr/bin/startx\"."
531 if [[ -e /etc/X11/xorg.conf ]] ; then
532 [[ -x /usr/bin/xinit ]] && /usr/bin/xinit || /usr/X11R6/bin/xinit
534 echo "Please use the script \"grml-x\" for starting the X Window System.
535 because there does not exist /etc/X11/xorg.conf yet.
536 If you want to use xinit anyway please call \"/usr/bin/xinit\"."
541 if check_com -c 915resolution; then
543 echo "Please use 915resolution as resolution modifying tool for Intel \
549 #a1# Output version of running grml
550 alias grml-version='cat /etc/grml_version'
552 if check_com -c rebuildfstab ; then
553 #a1# Rebuild /etc/fstab
554 alias grml-rebuildfstab='rebuildfstab -v -r -config'
557 if check_com -c grml-debootstrap ; then
559 echo "Installing debian to harddisk is possible by using grml-debootstrap."
568 xsource "/etc/zsh/keephack"
571 #########################################
572 ## YOUR PERSONNAL STUFF HERE ##
573 #########################################
576 for file in $ZSHDIR/rc/local/*; do
580 # Delete remaining xfunctions