4 # for zsh 3.1.6 and newer (may work OK with earlier versions)
6 # by Adam Spiers <adam@spiers.net>
8 # Best viewed in emacs folding mode (folding.el).
9 # (That's what all the # {{{ and # }}} are for.)
11 # $Id: .zshrc,v 1.255 2004/03/15 21:24:26 adams Exp $
18 # - Do safes?kill(all)? functions
23 # {{{ What version are we running?
25 if ! (( $+ZSH_VERSION_TYPE )); then
26 if [[ $ZSH_VERSION == 3.0.<->* ]]; then ZSH_STABLE_VERSION=yes; fi
27 if [[ $ZSH_VERSION == 3.1.<->* ]]; then ZSH_DEVEL_VERSION=yes; fi
30 if [[ $ZSH_VERSION == 3.1.<6->* ||
31 $ZSH_VERSION == 3.<2->.<->* ||
32 $ZSH_VERSION == 4.<->* ]]
41 [[ -n "$ZSH_PROFILE_RC" ]] && which zmodload >&/dev/null && zmodload zsh/zprof
46 zshrc_load_status () {
47 # \e[0K is clear to right
48 echo -n "\r.zshrc load: $* ... \e[0K"
55 zshrc_load_status 'setting options'
86 NO_csh_junkie_quotes \
109 interactive_comments \
126 NO_print_exit_value \
136 NO_sh_file_expansion \
141 NO_sun_keyboard_hack \
146 if [[ $ZSH_VERSION_TYPE == 'new' ]]; then
148 hist_expire_dups_first \
149 hist_ignore_all_dups \
150 NO_hist_no_functions \
151 NO_hist_save_no_dups \
157 if [[ $ZSH_VERSION == 3.0.<6->* || $ZSH_VERSION_TYPE == 'new' ]]; then
165 zshrc_load_status 'setting environment'
169 [[ "$ZSH_VERSION_TYPE" == 'old' ]] || typeset -T INFOPATH infopath
170 typeset -U infopath # no duplicates
173 ~/local/$OSTYPE/info(N)
185 # Don't need to do anything through the cunningness
186 # of AUTOPATH in /etc/man.config!
190 # Don't trust system-wide MANPATH? Remember what it was, for reference.
191 sysmanpath=$HOME/.sysmanpath
192 [ -e $sysmanpath ] || echo "$MANPATH" > $sysmanpath
194 for dir in "$path[@]"; do
195 [[ "$dir" == */bin ]] || continue
196 mandir="${dir//\/bin//man}"
197 [[ -d "$mandir" ]] && manpath=( "$mandir" "$manpath[@]" )
200 # ... or *do* trust system-wide MANPATH
201 #MANPATH=/usr/local/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/sbin:/sbin:$MANPATH
207 # Variables used by zsh
209 # {{{ Choose word delimiter characters in line editor
214 # {{{ Save a large history
216 HISTFILE=~/.zshhistory
221 # {{{ Maximum size of completion listing
223 #LISTMAX=0 # Only ask if line would scroll off screen
224 LISTMAX=1000 # "Never" ask
227 # {{{ Watching for other users
230 WATCHFMT="[%B%t%b] %B%n%b has %a %B%l%b from %B%M%b"
238 # echo Inactivity timeout on $TTY
242 # echo Terminal unlocked. [ Press Enter ]
250 # Load the theme-able prompt system and use it to set a prompt.
251 # Probably only suitable for a dark background terminal.
253 local _find_promptinit
254 _find_promptinit=( $^fpath/promptinit(N) )
255 if (( $#_find_promptinit >= 1 )) && [[ -r $_find_promptinit[1] ]]; then
256 zshrc_load_status 'prompt system'
258 autoload -U promptinit
262 #RPS1="$bold_colour$bg_red $reset_colour"
264 # Default prompt style
265 adam2_colors=( white cyan cyan green )
267 if [[ -r $zdotdir/.zsh_prompt ]]; then
268 . $zdotdir/.zsh_prompt
271 if [[ -r /proc/$PPID/cmdline ]] &&
272 egrep -q 'watchlogs|kates|nexus|vga' /proc/$PPID/cmdline;
274 # probably OK for fancy graphic prompt
275 if [[ "`prompt -h adam2`" == *8bit* ]]; then
276 prompt adam2 8bit $adam2_colors
278 prompt adam2 $adam2_colors
281 if [[ "`prompt -h adam2`" == *plain* ]]; then
282 prompt adam2 plain $adam2_colors
284 prompt adam2 $adam2_colors
288 if [[ $TERM == tgtelnet ]]; then
292 PS1='%n@%m %B%3~%b %# '
299 zshrc_load_status 'completion system'
301 # {{{ Set up new advanced completion system
303 if [[ "$ZSH_VERSION_TYPE" == 'new' ]]; then
305 compinit -C # don't perform security check
307 print "\nAdvanced completion system not found; ignoring zstyle settings."
311 # an antiquated, barebones completion system is better than nowt
312 which zmodload >&/dev/null && zmodload zsh/compctl
316 # {{{ General completion technique
318 # zstyle ':completion:*' completer \
319 # _complete _prefix _approximate:-one _ignored \
320 # _complete:-extended _approximate:-four
321 zstyle ':completion:*' completer _complete _prefix _ignored _complete:-extended
323 zstyle ':completion::prefix-1:*' completer _complete
324 zstyle ':completion:incremental:*' completer _complete _correct
325 zstyle ':completion:predict:*' completer _complete
327 zstyle ':completion:*:approximate-one:*' max-errors 1
328 zstyle ':completion:*:approximate-four:*' max-errors 4
330 zstyle ':completion:*:complete-extended:*' \
331 matcher 'r:|[.,_-]=* r:|=*'
334 # {{{ Fancy menu selection when there's ambiguity
336 #zstyle ':completion:*' menu yes select interactive
337 #zstyle ':completion:*' menu yes=long select=long interactive
338 #zstyle ':completion:*' menu yes=10 select=10 interactive
341 # {{{ Completion caching
343 zstyle ':completion::complete:*' use-cache 1
344 zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
347 # {{{ Expand partial paths
349 zstyle ':completion:*' expand 'yes'
350 zstyle ':completion:*' squeeze-slashes 'yes'
353 # {{{ Include non-hidden dirs in globbed file completions for certain commands
355 #zstyle ':completion::complete:*' \
356 # tag-order 'globbed-files directories' all-files
357 #zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'
360 # {{{ Don't complete backup files as executables
362 zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
365 # {{{ Don't complete uninteresting users
367 zstyle ':completion:*:*:*:users' ignored-patterns \
368 adm apache bin daemon games gdm halt ident junkbust lp mail mailnull \
369 named news nfsnobody nobody nscd ntp operator pcap postgres radvd \
370 rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
372 # ... unless we really want to.
373 zstyle '*' single-ignored show
376 # {{{ Output formatting
378 # Separate matches into groups
379 zstyle ':completion:*:matches' group 'yes'
381 # Describe each match group.
382 zstyle ':completion:*:descriptions' format "%B---- %d%b"
384 # Messages/warnings format
385 zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
386 zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'
388 # Describe options in full
389 zstyle ':completion:*:options' description 'yes'
390 zstyle ':completion:*:options' auto-description '%d'
393 # {{{ Array/association subscripts
395 # When completing inside array or association subscripts, the array
396 # elements are more useful than parameters so complete them first:
397 zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
400 # {{{ Completion for 'kill'
402 zstyle ':completion:*:*:kill:*' menu yes select
403 zstyle ':completion:*:kill:*' force-list always
406 # {{{ Simulate my old dabbrev-expand 3.0.5 patch
408 zstyle ':completion:*:history-words' stop yes
409 zstyle ':completion:*:history-words' remove-all-dups yes
410 zstyle ':completion:*:history-words' list false
411 zstyle ':completion:*:history-words' menu yes
414 # {{{ Common usernames
416 # users=( tom dick harry )
418 #zstyle ':completion:*' users $users
421 # {{{ Common hostnames
423 if [[ "$ZSH_VERSION_TYPE" == 'new' ]]; then
424 : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
425 # _ssh_known_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*})
427 # Older versions don't like the above cruft
440 zstyle ':completion:*' hosts $hosts
443 # {{{ (user,host) pairs
447 # {joe,root}@mymachine.com
448 # jbloggs@myothermachine.com
451 zstyle ':completion:*:my-accounts' users-hosts $my_accounts
453 # Other people's accounts:
455 # {fred,root}@hismachine.com
456 # vera@hermachine.com
458 #zstyle ':completion:*:other-accounts' users-hosts $other_accounts
461 # {{{ (host, port, user) triples for telnet
463 # telnet_users_hosts_ports=(
466 # @mail-server:{smtp,pop3}
470 #zstyle ':completion:*:*:telnet:*' users-hosts-ports $telnet_users_hosts_ports
475 # {{{ Aliases and functions
477 zshrc_load_status 'aliases and functions'
481 # {{{ Better word navigation
483 # Remember, WORDCHARS is defined as a 'list of non-alphanumeric
484 # characters considered part of a word by the line editor'.
486 # Elsewhere we set it to the empty string.
488 _my_extended_wordchars='*?_-.[]~=&;!#$%^(){}<>:@,\\'
489 _my_extended_wordchars_space="${_my_extended_wordchars} "
490 _my_extended_wordchars_slash="${_my_extended_wordchars}/"
492 # is the current position \-quoted ?
493 is_backslash_quoted () {
494 test "${BUFFER[$CURSOR-1,CURSOR-1]}" = "\\"
497 unquote-forward-word () {
498 while is_backslash_quoted
503 unquote-backward-word () {
504 while is_backslash_quoted
505 do zle .backward-word
509 backward-to-space () {
510 local WORDCHARS="${_my_extended_wordchars_slash}"
512 unquote-backward-word
515 forward-to-space () {
516 local WORDCHARS="${_my_extended_wordchars_slash}"
522 local WORDCHARS="${_my_extended_wordchars}"
524 unquote-backward-word
528 local WORDCHARS="${_my_extended_wordchars}"
533 # Create new user-defined widgets pointing to eponymous functions.
534 zle -N backward-to-space
535 zle -N forward-to-space
540 # {{{ kill-region-or-backward-(big-)word
543 zle -N kill-region-or-backward-word
544 zle -N kill-region-or-backward-big-word
550 local WORDCHARS="${_my_extended_wordchars_slash}"
558 zle -N incremental-complete-word
568 # reverse unwanted aliasing of `which' by distribution startup
569 # files (e.g. /etc/profile.d/which*.sh); zsh's which is perfectly
572 alias which >&/dev/null && unalias which
579 alias run-help >&/dev/null && unalias run-help
588 # {{{ Restarting zsh or bash; reloading .zshrc or functions
591 NO_SWITCH="yes" command bash "$@"
595 exec $SHELL $SHELL_ARGS "$@"
599 ZSH_PROFILE_RC=1 $SHELL "$@"
603 if [[ "$#*" -eq 0 ]]; then
613 compdef _functions reload
618 if ls -F --color >&/dev/null; then
619 alias ls='command ls -F --color'
620 elif ls -F >&/dev/null; then
621 alias ls='command ls -F'
622 elif ls --color >&/dev/null; then
623 alias ls='command ls --color'
632 alias lsh='ls -dh .*'
637 alias lart='ls -larth'
641 alias sl=ls # often screw this up
644 # {{{ File management/navigation
646 # {{{ Changing/making/removing directory
649 alias -g ....=../../..
650 alias -g .....=../../../..
651 alias -g ......=../../../../..
653 alias cd...='cd ../..'
654 alias cd....='cd ../../..'
655 alias cd.....='cd ../../../..'
658 alias ../..='cd ../..'
659 alias ../../..='cd ../../..'
660 alias ../../../..='cd ../../../..'
661 alias ../../../../..='cd ../../../../..'
675 # Sweet trick from zshwiki.org :-)
677 if (( $# != 1 )); then
682 if [[ -f "$1" ]]; then
707 alias mmv='noglob zmv -W'
712 # {{{ Job/process control
720 alias h='history -$LINES'
732 alias term='echo $TERM'
733 # {{{ Changing terminal window/icon titles
735 which cx >&/dev/null || cx () { }
737 if [[ "$TERM" == ([Ex]term*|screen*) ]]; then
738 # Could also look at /proc/$PPID/cmdline ...
753 # su changes window title, even if we're not a login shell
760 # {{{ No spelling correction
762 alias man='nocorrect man'
763 alias mysql='nocorrect mysql'
764 alias mysqlshow='nocorrect mysqlshow'
765 alias mkdir='nocorrect mkdir'
766 alias mv='nocorrect mv'
767 alias rj='nocorrect rj'
770 # {{{ X windows related
772 # {{{ export DISPLAY=:0.0
774 alias sd='export DISPLAY=:0.0'
779 # {{{ Different CVS setups
812 if [[ -n "$OTHER_USER" ]]; then
813 emacs -l $ZDOTDIR/.emacs "$@" &!
820 alias pico='/usr/bin/pico -z'
822 if which vim >&/dev/null; then
830 cx -l "${(M)argv:#*@*}" # pick out user@host word from argv
835 # Best to run this from .zshrc.local
836 #dsa >&DN || echo "ssh-agent setup failed; run dsa."
841 if which lftp >&/dev/null; then
843 elif which ncftp >&/dev/null; then
848 # {{{ watching log files
851 alias tfs='less -S +F'
856 if which larch >&/dev/null; then
873 # WARNING: global aliases are evil. Use with caution.
875 # {{{ For screwed up keyboards missing pipe
880 # {{{ Paging with less / head / tail
883 alias -g LS='| less -S'
884 alias -g EL='|& less'
885 alias -g ELS='|& less -S'
888 alias -g HL='| head -20'
889 alias -g EH='|& head'
890 alias -g EHL='|& head -20'
893 alias -g TL='| tail -20'
894 alias -g ET='|& tail'
895 alias -g ETL='|& tail -20'
898 # {{{ Sorting / counting
903 alias -g US='| sort -u'
904 alias -g NS='| sort -n'
905 alias -g RNS='| sort -nr'
908 # {{{ Common filenames
910 alias -g DN=/dev/null
911 alias -g VM=/var/log/messages
917 alias -g EG='|& egrep'
919 alias -g X0='| xargs -0'
920 alias -g XG='| xargs egrep'
921 alias -g X0G='| xargs -0 egrep'
930 zshrc_load_status 'key bindings'
932 bindkey -s '^X^Z' '%-^M'
933 bindkey '^[e' expand-cmd-path
934 #bindkey -s '^X?' '\eb=\ef\C-x*'
935 bindkey '^[^I' reverse-menu-complete
936 bindkey '^X^N' accept-and-infer-next-history
937 bindkey '^[p' history-beginning-search-backward
938 bindkey '^[n' history-beginning-search-forward
939 bindkey '^[P' history-beginning-search-backward
940 bindkey '^[N' history-beginning-search-forward
941 bindkey '^w' kill-region-or-backward-word
942 bindkey '^[^W' kill-region-or-backward-big-word
943 bindkey '^I' complete-word
944 bindkey '^Xi' incremental-complete-word
945 # bindkey '^[b' emacs-backward-word
946 # bindkey '^[f' emacs-forward-word
947 bindkey '^[B' backward-to-space
948 bindkey '^[F' forward-to-space
949 bindkey '^[^b' backward-to-/
950 bindkey '^[^f' forward-to-/
952 bindkey '^[D' kill-big-word
954 if zmodload zsh/deltochar >&/dev/null; then
955 bindkey '^[z' zap-to-char
956 bindkey '^[Z' delete-to-char
959 # Fix weird sequence that rxvt produces
960 bindkey -s '^[[Z' '\t'
962 alias no=ls # for Dvorak
967 zshrc_load_status 'miscellaneous'
969 # {{{ Hash named directories
971 # cdable_vars is set, so don't need 'hash -d' in front of these
972 RP=/usr/src/redhat/RPMS
973 I3=/usr/src/redhat/RPMS/i386
974 I4=/usr/src/redhat/RPMS/i486
975 I5=/usr/src/redhat/RPMS/i586
976 I6=/usr/src/redhat/RPMS/i686
977 NA=/usr/src/redhat/RPMS/noarch
978 SR=/usr/src/redhat/SRPMS
979 SP=/usr/src/redhat/SPECS
980 SO=/usr/src/redhat/SOURCES
981 BU=/usr/src/redhat/BUILD
983 L4=/usr/src/linux-2.4
984 CV=/usr/local/cvsroot
992 if which dircolors >&/dev/null && [[ -e "${zdotdir}/.dircolors" ]]; then
993 eval "`dircolors -b $zdotdir/.dircolors`"
996 if [[ $ZSH_VERSION > 3.1.5 ]]; then
997 zmodload -i zsh/complist
999 zstyle ':completion:*' list-colors ''
1001 zstyle ':completion:*:*:kill:*:processes' list-colors \
1002 '=(#b) #([0-9]#)*=0=01;31'
1004 # completion colours
1005 zstyle ':completion:*' list-colors "$LS_COLORS"
1009 # {{{ Don't always autologout
1011 if [[ "${TERM}" == ([Ex]term*|dtterm|screen*) ]]; then
1019 # {{{ Specific to local setups
1021 zshrc_load_status 'local hooks'
1022 run_local_hooks .zshrc
1026 # {{{ Clear up after status display
1028 if [[ $TERM == tgtelnet ]]; then
1035 # {{{ Profile report
1037 if [[ -n "$ZSH_PROFILE_RC" ]]; then
1038 zprof >! ~/zshrc.zprof
1044 # {{{ Search for history loosing bug
1046 which check_hist_size >&/dev/null && check_hist_size