shosei

zshrc

May 8th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 24.85 KB | None | 0 0
  1. #!/bin/zsh
  2. #
  3. # .zshrc
  4. # for zsh 3.1.6 and newer (may work OK with earlier versions)
  5. #
  6. # by Adam Spiers <[email protected]>
  7. #
  8. # Best viewed in emacs folding mode (folding.el).
  9. # (That's what all the # {{{ and # }}} are for.)
  10. #
  11. # $Id$
  12. #
  13.  
  14. [ -n "$INHERIT_ENV" ] && return 0
  15.  
  16. # {{{ To do list
  17.  
  18. #
  19. #    - du1
  20. #    - Do safes?kill(all)? functions
  21. #
  22.  
  23. # }}}
  24.  
  25. sh_load_status .zshrc
  26.  
  27. # {{{ What version are we running?
  28.  
  29. if ! (( $+ZSH_VERSION_TYPE )); then
  30.   if [[ $ZSH_VERSION == 3.0.<->* ]]; then ZSH_STABLE_VERSION=yes; fi
  31.   if [[ $ZSH_VERSION == 3.1.<->* ]]; then ZSH_DEVEL_VERSION=yes;  fi
  32.  
  33.   ZSH_VERSION_TYPE=old
  34.   if [[ $ZSH_VERSION == 3.1.<6->* ||
  35.         $ZSH_VERSION == 3.<2->.<->*  ||
  36.         $ZSH_VERSION == 4.<->* ]]
  37.   then
  38.     ZSH_VERSION_TYPE=new
  39.   fi
  40. fi
  41.  
  42. # }}}
  43. # {{{ Profiling
  44.  
  45. [[ -n "$ZSH_PROFILE_RC" ]] && which zmodload >&/dev/null && zmodload zsh/zprof
  46.  
  47. # }}}
  48.  
  49. # {{{ Options
  50.  
  51. sh_load_status 'setting options'
  52.  
  53. setopt                       \
  54.      NO_all_export           \
  55.         always_last_prompt   \
  56.      NO_always_to_end        \
  57.         append_history       \
  58.         auto_cd              \
  59.         auto_list            \
  60.         auto_menu            \
  61.      NO_auto_name_dirs       \
  62.         auto_param_keys      \
  63.         auto_param_slash     \
  64.         auto_pushd           \
  65.         auto_remove_slash    \
  66.      NO_auto_resume          \
  67.         bad_pattern          \
  68.         bang_hist            \
  69.      NO_beep                 \
  70.      NO_brace_ccl            \
  71.         correct_all          \
  72.      NO_bsd_echo             \
  73.         cdable_vars          \
  74.      NO_chase_links          \
  75.      NO_clobber              \
  76.         complete_aliases     \
  77.         complete_in_word     \
  78.      NO_correct              \
  79.         correct_all          \
  80.         csh_junkie_history   \
  81.      NO_csh_junkie_loops     \
  82.      NO_csh_junkie_quotes    \
  83.      NO_csh_null_glob        \
  84.         equals               \
  85.         extended_glob        \
  86.         extended_history     \
  87.         function_argzero     \
  88.         glob                 \
  89.      NO_glob_assign          \
  90.         glob_complete        \
  91.      NO_glob_dots            \
  92.         glob_subst           \
  93.      NO_hash_cmds            \
  94.         hash_dirs            \
  95.         hash_list_all        \
  96.         hist_allow_clobber   \
  97.         hist_beep            \
  98.         hist_ignore_dups     \
  99.         hist_ignore_space    \
  100.      NO_hist_no_store        \
  101.         hist_verify          \
  102.      NO_hup                  \
  103.      NO_ignore_braces        \
  104.      NO_ignore_eof           \
  105.         interactive_comments \
  106.      NO_ksh_glob             \
  107.      NO_list_ambiguous       \
  108.      NO_list_beep            \
  109.         list_types           \
  110.         long_list_jobs       \
  111.         magic_equal_subst    \
  112.      NO_mail_warning         \
  113.      NO_mark_dirs            \
  114.      NO_menu_complete        \
  115.         multios              \
  116.      NO_nomatch              \
  117.         notify               \
  118.      NO_null_glob            \
  119.         numeric_glob_sort    \
  120.      NO_overstrike           \
  121.         path_dirs            \
  122.         posix_builtins       \
  123.      NO_print_exit_value     \
  124.      NO_prompt_cr            \
  125.         prompt_subst         \
  126.         pushd_ignore_dups    \
  127.      NO_pushd_minus          \
  128.         pushd_silent         \
  129.         pushd_to_home        \
  130.         rc_expand_param      \
  131.      NO_rc_quotes            \
  132.      NO_rm_star_silent       \
  133.      NO_sh_file_expansion    \
  134.         sh_option_letters    \
  135.         short_loops          \
  136.         sh_word_split        \
  137.      NO_single_line_zle      \
  138.      NO_sun_keyboard_hack    \
  139.         unset                \
  140.      NO_verbose              \
  141.         zle
  142.  
  143. if [[ $ZSH_VERSION_TYPE == 'new' ]]; then
  144.   setopt                       \
  145.      NO_hist_expire_dups_first \
  146.         hist_find_no_dups      \
  147.      NO_hist_ignore_all_dups   \
  148.      NO_hist_no_functions      \
  149.      NO_hist_save_no_dups      \
  150.         inc_append_history     \
  151.         list_packed            \
  152.      NO_rm_star_wait
  153. fi
  154.  
  155. if [[ $ZSH_VERSION == 3.0.<6->* || $ZSH_VERSION_TYPE == 'new' ]]; then
  156.   setopt \
  157.         hist_reduce_blanks
  158. fi
  159.  
  160. # }}}
  161. # {{{ Environment
  162.  
  163. sh_load_status 'setting environment'
  164.  
  165. # {{{ INFOPATH
  166.  
  167. [[ "$ZSH_VERSION_TYPE" == 'old' ]] || typeset -T INFOPATH infopath
  168. typeset -U infopath # no duplicates
  169. export INFOPATH
  170. infopath=(
  171.           ~/local/$OSTYPE/{share/,}info(N)
  172.           ~/{local/,}{share/,}info(N)
  173.           /usr/{local/,}{share/,}info(N)
  174.           $infopath
  175.          )
  176.  
  177. # }}}
  178. # {{{ MANPATH
  179.  
  180. case "$OSTYPE" in
  181.   linux*)
  182.     # Don't need to do anything through the cunningness
  183.     # of AUTOPATH in /etc/manpath.config!
  184.     ;;
  185.  
  186.   *)
  187.     # Don't trust system-wide MANPATH?  Remember what it was, for reference.
  188.     sysmanpath=$HOME/.sysmanpath.$HOST
  189.     [ -e $sysmanpath ] || echo "$MANPATH" > $sysmanpath
  190.     manpath=( )
  191.  
  192.     # ... or *do* trust system-wide MANPATH
  193.     #MANPATH=/usr/local/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/sbin:/sbin:$MANPATH
  194.  
  195.     for dir in "$path[@]"; do
  196.       [[ "$dir" == */bin ]] || continue
  197.       mandir="${dir//\/bin//man}"
  198.       [[ -d "$mandir" ]] && manpath=( "$mandir" "$manpath[@]" )
  199.     done
  200.  
  201.     ;;
  202. esac
  203.  
  204. # Add extra paths to path determined by /etc/man.config
  205. MANPATH="`MANPATH= manpath`"
  206. manpath=(
  207.     $ZDOTDIR/{local/,}share/[m]an(N)
  208.     "$manpath[@]"
  209. )
  210.  
  211. # }}}
  212. # {{{ LANG
  213.  
  214. # Eterm sucks
  215. if [[ "$LANG" == *UTF-8 ]] && grep Eterm /proc/$PPID/cmdline >&/dev/null; then
  216.     LANG="${LANG%.UTF-8}"
  217. fi
  218.  
  219. # }}}
  220.  
  221. # Variables used by zsh
  222.  
  223. # {{{ Choose word delimiter characters in line editor
  224.  
  225. # The manual defines WORDCHARS as "a list of non-alphanumeric
  226. # characters considered part of a word by the line editor."
  227. # Nevertheless the effect is not intuitive and best understood by
  228. # experimenting with the value.
  229. WORDCHARS='>~'
  230.  
  231. # }}}
  232. # {{{ Save a large history
  233.  
  234. HISTFILE=~/.zshhistory
  235. HISTSIZE=3000
  236. SAVEHIST=3000
  237.  
  238. # }}}
  239. # {{{ Maximum size of completion listing
  240.  
  241. #LISTMAX=0    # Only ask if line would scroll off screen
  242. LISTMAX=1000  # "Never" ask
  243.  
  244. # }}}
  245. # {{{ Watching for other users
  246.  
  247. LOGCHECK=60
  248. WATCHFMT="[%B%t%b] %B%n%b has %a %B%l%b from %B%M%b"
  249.  
  250. # }}}
  251. # {{{ Auto logout
  252.  
  253. TMOUT=1800
  254. #TRAPALRM () {
  255. #  clear
  256. #  echo Inactivity timeout on $TTY
  257. #  echo
  258. #  vlock -c
  259. #  echo
  260. #  echo Terminal unlocked. [ Press Enter ]
  261. #}
  262.  
  263. # }}}
  264.  
  265. # }}}
  266. # {{{ Prompts
  267.  
  268. # Load the theme-able prompt system and use it to set a prompt.
  269. # Probably only suitable for a dark background terminal.
  270.  
  271. local _find_promptinit
  272. _find_promptinit=( $^fpath/promptinit(N) )
  273. if (( $#_find_promptinit >= 1 )) && [[ -r $_find_promptinit[1] ]]; then
  274.   sh_load_status 'prompt system'
  275.  
  276.   autoload -U promptinit
  277.   promptinit
  278.  
  279.   PS4="trace %N:%i> "
  280.   #RPS1="$bold_colour$bg_red              $reset_colour"
  281.  
  282.   # Default prompt style
  283.   adam2_colors=( white cyan cyan green )
  284.  
  285.   if [[ -r $zdotdir/.zsh_prompt ]]; then
  286.     . $zdotdir/.zsh_prompt
  287.   fi
  288.  
  289.   if [[ -r /proc/$PPID/cmdline ]] &&
  290.        egrep -q 'watchlogs|kates|nexus|vga' /proc/$PPID/cmdline;
  291.   then
  292.     # probably OK for fancy graphic prompt
  293.     if [[ "`prompt -h adam2`" == *8bit* ]]; then
  294.       prompt adam2 8bit $adam2_colors
  295.     else
  296.       prompt adam2 $adam2_colors
  297.     fi
  298.   else
  299.     if [[ "`prompt -h adam2`" == *plain* ]]; then
  300.       prompt adam2 plain $adam2_colors
  301.     else
  302.       prompt adam2 $adam2_colors
  303.     fi
  304.   fi
  305.  
  306.   # TopGun ssh for Palm
  307.   case "$TERM" in
  308.       tgtelnet) prompt off ;;
  309.       dumb)
  310.           # Make sure emacs tramp.el doesn't hang.
  311.           # The default value of tramp-shell-prompt-regexp gets confused
  312.           # by CR carriage return characters unless you change the first
  313.           # ^ to \\(^|^M\\) (N.B. ^M would need to be the raw character
  314.           # in that).  But instead we can just stop zsh producing them.
  315.  
  316.           # Note that zsh's 'off' prompt theme's prompt_opts causes
  317.           # prompt_cr to be enabled.
  318.           #prompt off
  319.           #setopt no_prompt_cr
  320.  
  321.           # Or we can make our own "theme" right here:
  322.           functions precmd  >/dev/null && unfunction precmd
  323.           functions preexec >/dev/null && unfunction preexec
  324.           setopt no_prompt_cr prompt_subst no_prompt_bang prompt_percent
  325.           PS1="[%n@%m %1~]\$ "
  326.           PS2="> "
  327.  
  328.           # http://www.emacswiki.org/emacs/TrampMode#toc3 suggests these too
  329.           # but I don't seem to need them:
  330.           #unsetopt zle
  331.           #unsetopt prompt_subst
  332.           ;;
  333.   esac
  334. else
  335.   PS1='%n@%m %B%3~%b %# '
  336. fi
  337.  
  338. # }}}
  339.  
  340. # {{{ Completions
  341.  
  342. sh_load_status 'completion system'
  343.  
  344. # {{{ Set up new advanced completion system
  345.  
  346. if [[ "$ZSH_VERSION_TYPE" == 'new' ]]; then
  347.   autoload -Uz compinit
  348.   zstyle :compinstall filename '/home/adam/.zshrc'
  349.   compinit -u # use with care!!
  350. else
  351.   print "\nAdvanced completion system not found; ignoring zstyle settings."
  352.   function zstyle { }
  353.   function compdef { }
  354.  
  355.   # an antiquated, barebones completion system is better than nowt
  356.   which zmodload >&/dev/null && zmodload zsh/compctl
  357. fi
  358.  
  359. # }}}
  360. # {{{ General completion technique
  361.  
  362. # zstyle ':completion:*' completer \
  363. #   _complete _prefix _approximate:-one _ignored \
  364. #   _complete:-extended _approximate:-four
  365. zstyle ':completion:*' completer _complete _prefix _ignored _complete:-extended
  366.  
  367. zstyle ':completion::prefix-1:*' completer _complete
  368. zstyle ':completion:incremental:*' completer _complete _correct
  369. zstyle ':completion:predict:*' completer _complete
  370.  
  371. zstyle ':completion:*:approximate-one:*'  max-errors 1
  372. zstyle ':completion:*:approximate-four:*' max-errors 4
  373.  
  374. # e.g. f-1.j<TAB> would complete to foo-123.jpeg
  375. zstyle ':completion:*:complete-extended:*' \
  376.   matcher 'r:|[.,_-]=* r:|=*'
  377.  
  378. # }}}
  379. # {{{ Fancy menu selection when there's ambiguity
  380.  
  381. #zstyle ':completion:*' menu yes select interactive
  382. #zstyle ':completion:*' menu yes=long select=long interactive
  383. #zstyle ':completion:*' menu yes=10 select=10 interactive
  384.  
  385. # }}}
  386. # {{{ Completion caching
  387.  
  388. zstyle ':completion::complete:*' use-cache 1
  389. zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
  390.  
  391. # }}}
  392. # {{{ Expand partial paths
  393.  
  394. # e.g. /u/s/l/D/fs<TAB> would complete to
  395. #      /usr/src/linux/Documentation/fs
  396. zstyle ':completion:*' expand 'yes'
  397. zstyle ':completion:*' squeeze-slashes 'yes'
  398.  
  399. # }}}
  400. # {{{ Include non-hidden dirs in globbed file completions for certain commands
  401.  
  402. #zstyle ':completion::complete:*' \
  403. #  tag-order 'globbed-files directories' all-files
  404. #zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'
  405.  
  406. # }}}
  407. # {{{ Don't complete backup files (e.g. 'bin/foo~') as executables
  408.  
  409. zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
  410.  
  411. # }}}
  412. # {{{ Don't complete uninteresting users
  413.  
  414. zstyle ':completion:*:*:*:users' ignored-patterns \
  415.         adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
  416.         dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
  417.         hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
  418.         mailman mailnull mldonkey mysql nagios \
  419.         named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
  420.         operator pcap postfix postgres privoxy pulse pvm quagga radvd \
  421.         rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
  422.  
  423. # ... unless we really want to.
  424. zstyle '*' single-ignored show
  425.  
  426. # }}}
  427. # {{{ Output formatting
  428.  
  429. # Separate matches into groups
  430. zstyle ':completion:*:matches' group 'yes'
  431.  
  432. # Describe each match group.
  433. zstyle ':completion:*:descriptions' format "%B---- %d%b"
  434.  
  435. # Messages/warnings format
  436. zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
  437. zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'
  438.  
  439. # Describe options in full
  440. zstyle ':completion:*:options' description 'yes'
  441. zstyle ':completion:*:options' auto-description '%d'
  442.  
  443. # }}}
  444. # {{{ Array/association subscripts
  445.  
  446. # When completing inside array or association subscripts, the array
  447. # elements are more useful than parameters so complete them first:
  448. zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
  449.  
  450. # }}}
  451. # {{{ Completion for processes
  452.  
  453. zstyle ':completion:*:*:*:*:processes' menu yes select
  454. zstyle ':completion:*:*:*:*:processes' force-list always
  455.  
  456. # }}}
  457. # {{{ Simulate my old dabbrev-expand 3.0.5 patch
  458.  
  459. zstyle ':completion:*:history-words' stop yes
  460. zstyle ':completion:*:history-words' remove-all-dups yes
  461. zstyle ':completion:*:history-words' list false
  462. zstyle ':completion:*:history-words' menu yes
  463.  
  464. # }}}
  465. # {{{ Usernames
  466.  
  467. run_hooks .zsh/users.d
  468. zstyle ':completion:*' users $zsh_users
  469.  
  470. # }}}
  471. # {{{ Hostnames
  472.  
  473. if [[ "$ZSH_VERSION_TYPE" == 'new' ]]; then
  474.   # Extract hosts from /etc/hosts
  475.   # ~~ no glob_subst -> don't treat contents of /etc/hosts like pattern
  476.   # (f) shorthand for (ps:\n:) -> split on \n ((p) enables recognition of \n etc.)
  477.   # %%\#* -> remove comment lines and trailing comments
  478.   # (ps:\t:) -> split on tab
  479.   # ##[:blank:]#[^[:blank:]]# -> remove comment lines
  480.  
  481.   : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
  482. # _ssh_known_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*})
  483. else
  484.   # Older versions don't like the above cruft
  485.   _etc_hosts=()
  486. fi
  487.  
  488. zsh_hosts=(
  489.     "$_etc_hosts[@]"
  490.     localhost
  491. )
  492.  
  493. run_hooks .zsh/hosts.d
  494. zstyle ':completion:*' hosts $zsh_hosts
  495.  
  496. # }}}
  497. # {{{ (user, host) account pairs
  498.  
  499. run_hooks .zsh/accounts.d
  500. zstyle ':completion:*:my-accounts'    users-hosts "$my_accounts[@]"
  501. zstyle ':completion:*:other-accounts' users-hosts "$other_accounts[@]"
  502.  
  503. # }}}
  504.  
  505. # {{{ pdf
  506.  
  507. compdef _pdf pdf
  508.  
  509. # }}}
  510.  
  511. # }}}
  512. # {{{ Aliases and functions
  513.  
  514. sh_load_status 'aliases and functions'
  515.  
  516. # {{{ Motion/editing
  517.  
  518. # {{{ Better word navigation
  519.  
  520. # Remember, WORDCHARS is defined as a 'list of non-alphanumeric
  521. # characters considered part of a word by the line editor'.
  522.  
  523. # Elsewhere we set it to the empty string.
  524.  
  525. _my_extended_wordchars='*?_-.[]~=&;!#$%^(){}<>:@,\\'
  526. _my_extended_wordchars_space="${_my_extended_wordchars} "
  527. _my_extended_wordchars_slash="${_my_extended_wordchars}/"
  528.  
  529. # is the current position \-quoted ?
  530. is_backslash_quoted () {
  531.     test "${BUFFER[$CURSOR-1,CURSOR-1]}" = "\\"
  532. }
  533.  
  534. unquote-forward-word () {
  535.    while is_backslash_quoted
  536.      do zle .forward-word
  537.    done
  538. }
  539.  
  540. unquote-backward-word () {
  541.    while is_backslash_quoted
  542.      do zle .backward-word
  543.    done
  544. }
  545.  
  546. backward-to-space () {
  547.    local WORDCHARS="${_my_extended_wordchars_slash}"
  548.    zle .backward-word
  549.    unquote-backward-word
  550. }
  551.  
  552. forward-to-space () {
  553.     local WORDCHARS="${_my_extended_wordchars_slash}"
  554.     zle .forward-word
  555.     unquote-forward-word
  556. }
  557.  
  558. backward-to-/ () {
  559.    local WORDCHARS="${_my_extended_wordchars}"
  560.    zle .backward-word
  561.    unquote-backward-word
  562. }
  563.  
  564. forward-to-/ () {
  565.     local WORDCHARS="${_my_extended_wordchars}"
  566.     zle .forward-word
  567.     unquote-forward-word
  568. }
  569.  
  570. # Create new user-defined widgets pointing to eponymous functions.
  571. zle -N backward-to-space
  572. zle -N forward-to-space
  573. zle -N backward-to-/
  574. zle -N forward-to-/
  575.  
  576. # }}}
  577. # {{{ kill-region-or-backward-(big-)word
  578.  
  579. # autoloaded
  580. zle -N kill-region-or-backward-word
  581. zle -N kill-region-or-backward-big-word
  582.  
  583. # }}}
  584. # {{{ kill-big-word
  585.  
  586. kill-big-word () {
  587.    local WORDCHARS="${_my_extended_wordchars_slash}"
  588.    zle .kill-word
  589. }
  590.  
  591. zle -N kill-big-word
  592.  
  593. # }}}
  594. # {{{ transpose-big-words
  595.  
  596. # autoloaded
  597. zle -N transpose-big-words
  598.  
  599. # }}}
  600. # {{{ magic-forward-char
  601.  
  602. zle -N magic-forward-char
  603.  
  604. # }}}
  605. # {{{ magic-forward-word
  606.  
  607. zle -N magic-forward-word
  608.  
  609. # }}}
  610. # {{{ incremental-complete-word
  611.  
  612. # doesn't work?
  613. zle -N incremental-complete-word
  614.  
  615. # }}}
  616.  
  617. # }}}
  618. # {{{ zrecompile
  619.  
  620. autoload zrecompile
  621.  
  622. # }}}
  623. # {{{ which/where
  624.  
  625. # reverse unwanted aliasing of `which' by distribution startup
  626. # files (e.g. /etc/profile.d/which*.sh); zsh's 'which' is perfectly
  627. # good as is.
  628.  
  629. alias which >&/dev/null && unalias which
  630.  
  631. # }}}
  632. # {{{ run-help
  633.  
  634. alias run-help >&/dev/null && unalias run-help
  635. autoload run-help
  636.  
  637. # }}}
  638. # {{{ zcalc
  639.  
  640. autoload zcalc
  641.  
  642. # }}}
  643. # {{{ Restarting zsh or bash; reloading .zshrc or functions
  644.  
  645. bash () {
  646.  NO_SWITCH="yes" command bash "$@"
  647. }
  648.  
  649. restart () {
  650.  if jobs | grep . >/dev/null; then
  651.    echo "Jobs running; won't restart." >&2
  652.    jobs -l >&2
  653.  else
  654.    exec $SHELL $SHELL_ARGS "$@"
  655.  fi
  656. }
  657. alias rstt=restart
  658.  
  659. profile () {
  660.  ZSH_PROFILE_RC=1 $SHELL "$@"
  661. }
  662.  
  663. reload () {
  664.  if [[ "$#*" -eq 0 ]]; then
  665.    . $zdotdir/.zshrc
  666.  else
  667.    local fn
  668.    for fn in "$@"; do
  669.      unfunction $fn
  670.      autoload -U $fn
  671.    done
  672.  fi
  673. }
  674. compdef _functions reload
  675.  
  676. # }}}
  677. # {{{ ls aliases
  678.  
  679. if ls -F --color / >&/dev/null; then
  680.    LS_OPTS='-F --color'
  681. elif ls -F / >&/dev/null; then
  682.    LS_OPTS='-F'
  683. elif ls --color / >&/dev/null; then
  684.    LS_OPTS='--color'
  685. fi
  686.  
  687. # jeez I'm lazy ...
  688. for opts in {,a}{,r}{,t}{,L}{,S}; do
  689.    eval "alias l$opts='ls -lh$opts $LS_OPTS'"
  690.    eval "alias ll$opts='ls -l$opts $LS_OPTS'"
  691.    eval "alias ls$opts='ls ${opts:+-$opts} $LS_OPTS'"
  692. done
  693.  
  694. alias ld='ls -ldh'
  695. alias sl=ls # often screw this up
  696.  
  697. # }}}
  698. # {{{ File management/navigation
  699.  
  700. # {{{ Changing/making/removing directory
  701.  
  702. alias -g ...=../..
  703. alias -g ....=../../..
  704. alias -g .....=../../../..
  705. alias -g ......=../../../../..
  706. alias cd..='cd ..'
  707. alias cd...='cd ../..'
  708. alias cd....='cd ../../..'
  709. alias cd.....='cd ../../../..'
  710. # blegh
  711. alias ..='cd ..'
  712. alias ../..='cd ../..'
  713. alias ../../..='cd ../../..'
  714. alias ../../../..='cd ../../../..'
  715. alias ../../../../..='cd ../../../../..'
  716.  
  717. alias cd/='cd /'
  718.  
  719. alias 1='cd -'
  720. alias 2='cd +2'
  721. alias 3='cd +3'
  722. alias 4='cd +4'
  723. alias 5='cd +5'
  724. alias 6='cd +6'
  725. alias 7='cd +7'
  726. alias 8='cd +8'
  727. alias 9='cd +9'
  728.  
  729. # Sweet trick from zshwiki.org :-)
  730. cd () {
  731.  if (( $# != 1 )); then
  732.    builtin cd "$@"
  733.    return
  734.  fi
  735.  
  736.  if [[ -f "$1" ]]; then
  737.    builtin cd "$1:h"
  738.  else
  739.    builtin cd "$1"
  740.  fi
  741. }
  742.  
  743. z () {
  744.  cd ~/"$1"
  745. }
  746.  
  747. alias md='mkdir -p'
  748. alias rd=rmdir
  749.  
  750. alias d='dirs -v'
  751.  
  752. po () {
  753.  popd "$@"
  754.  dirs -v
  755. }
  756.  
  757. # }}}
  758. # {{{ Renaming
  759.  
  760. autoload zmv
  761. alias mmv='noglob zmv -W'
  762.  
  763. # }}}
  764. # {{{ tree
  765.  
  766. alias tre='tree -C'
  767.  
  768. # }}}
  769.  
  770. # }}}
  771. # {{{ Job/process control
  772.  
  773. alias j='jobs -l'
  774. alias dn=disown
  775. compdef _jobs_fg dn
  776.  
  777. # }}}
  778. # {{{ History
  779.  
  780. alias h='history -f 1 | less +G'
  781. alias hh='history'
  782.  
  783. # }}}
  784. # {{{ Environment
  785.  
  786. alias ts=typeset
  787. compdef _typeset ts
  788.  
  789. # }}}
  790. # {{{ Terminal
  791.  
  792. alias cls='clear'
  793. alias term='echo $TERM'
  794. # {{{ Changing terminal window/icon titles
  795.  
  796. which cx >&/dev/null || cx () { }
  797.  
  798. if [[ "$TERM" == ([Ex]term*|rxvt*|screen*) ]]; then
  799.  # Could also look at /proc/$PPID/cmdline ...
  800.  cx
  801. fi
  802.  
  803. # }}}
  804. alias sc=screen
  805.  
  806. # }}}
  807. # {{{ Other users
  808.  
  809. compdef _users lh
  810.  
  811. alias f='finger -m'
  812. compdef _finger f
  813.  
  814. # su changes window title, even if we're not a login shell
  815. su () {
  816.  command su "$@"
  817.  cx
  818. }
  819.  
  820. # So does sux in SUSE
  821. sux () {
  822.  command sux "$@"
  823.  cx
  824. }
  825.  
  826. # }}}
  827. # {{{ No spelling correction
  828.  
  829. alias man='nocorrect man'
  830. alias mysql='nocorrect mysql'
  831. alias mysqlshow='nocorrect mysqlshow'
  832. alias mkdir='nocorrect mkdir'
  833. alias mv='nocorrect mv'
  834. alias rj='nocorrect rj'
  835. alias yast='nocorrect yast'
  836. alias yast2='nocorrect yast2'
  837.  
  838. # }}}
  839. # {{{ X windows related
  840.  
  841. # {{{ export DISPLAY=:0.0
  842.  
  843. alias sd='export DISPLAY=:0.0'
  844.  
  845. # }}}
  846.  
  847. # }}}
  848. # {{{ Different CVS setups
  849.  
  850. # Sensible defaults
  851. unset CVS_SERVER
  852. export CVSROOT
  853. export CVS_RSH=ssh
  854.  
  855. # see scvs function
  856.  
  857. # }}}
  858. # {{{ MIME handling
  859.  
  860. autoload zsh-mime-setup
  861. zsh-mime-setup
  862.  
  863. # }}}
  864. # {{{ Other programs
  865.  
  866. # {{{ less
  867.  
  868. if ! which less >&/dev/null; then
  869.  alias less=more
  870. fi
  871.  
  872. alias v=less
  873. alias vs='less -S'
  874.  
  875. # }}}
  876. # {{{ editors
  877.  
  878. # enable ^Z
  879. alias pico='/usr/bin/pico -z'
  880.  
  881. if which vim >&/dev/null; then
  882.    alias vi=vim
  883. fi
  884.  
  885. # }}}
  886. # {{{ arch
  887.  
  888. if which larch >&/dev/null; then
  889.  alias a=larch
  890.  compdef _larch a
  891. fi
  892.  
  893. # }}}
  894. # {{{ bzip2
  895.  
  896. alias bz=bzip2
  897. alias buz=bunzip2
  898.  
  899. # }}}
  900.  
  901. # }}}
  902.  
  903. # {{{ Global aliases
  904.  
  905. # WARNING: global aliases are evil.  Use with caution.
  906.  
  907. # {{{ For screwed up keyboards missing pipe
  908.  
  909. alias -g PIPE='|'
  910.  
  911. # }}}
  912. # {{{ Lists of pipelines
  913.  
  914. alias -g AD='&& div &&'
  915.  
  916. # }}}
  917.  
  918. # {{{ Paging with less / head / tail
  919.  
  920. alias -g L='| less'
  921. alias -g LS='| less -S'
  922. alias -g EL='|& less'
  923. alias -g ELS='|& less -S'
  924. alias -g TRIM='| trim-lines'
  925.  
  926. alias -g H='| head'
  927. alias -g HL='| head -n $(( +LINES ? LINES - 4 : 20 ))'
  928. alias -g EH='|& head'
  929. alias -g EHL='|& head -n $(( +LINES ? LINES - 4 : 20 ))'
  930.  
  931. alias -g T='| tail'
  932. alias -g TL='| tail -n $(( +LINES ? LINES - 4 : 20 ))'
  933. alias -g ET='|& tail'
  934. alias -g ETL='|& tail -n $(( +LINES ? LINES - 4 : 20 ))'
  935.  
  936. # }}}
  937. # {{{ Sorting / counting
  938.  
  939. alias -g C='| wc -l'
  940.  
  941. alias -g S='| sort'
  942. alias -g Su='| sort -u'
  943. alias -g Sn='| sort -n'
  944. alias -g Snr='| sort -nr'
  945. alias -g SUc='| sort | uniq -c'
  946. alias -g SUd='| sort | uniq -d'
  947. alias -g Uc='| uniq -c'
  948. alias -g Ud='| uniq -d'
  949.  
  950. # }}}
  951. # {{{ Common filenames
  952.  
  953. alias -g DN=/dev/null
  954. alias -g DZ=/dev/zero
  955. alias -g VM=/var/log/messages
  956.  
  957. # }}}
  958. # {{{ grep, xargs
  959.  
  960. # see also grep-shortcuts script
  961. for global_alias_switches in {,i}{,l,L}{,r}{,v}{,C}; do
  962.    case "$global_alias_switches" in
  963.        *C*)
  964.            rhs_switches="${global_alias_switches//C/}"
  965.            color=--color=always
  966.            ;;
  967.        *)
  968.            rhs_switches="$global_alias_switches"
  969.            color=
  970.            ;;
  971.    esac
  972.  
  973.    [ -n "$rhs_switches" ] && rhs_switches="-$rhs_switches"
  974.  
  975.    eval "alias -g  G$global_alias_switches='| egrep $rhs_switches $color'"
  976.    eval "alias -g EG$global_alias_switches='|& egrep $rhs_switches $color'"
  977.    eval "alias -g XG$global_alias_switches='| xargs egrep $rhs_switches $color'"
  978.    eval "alias -g X0G$global_alias_switches='| xargs -0 egrep $rhs_switches $color'"
  979. done
  980.  
  981. alias -g XA='| xargs'
  982. alias -g X1='| xargs -n1'
  983. alias -g X0='| xargs -0'
  984. alias -g Xn='| xargs -d "\n"'
  985.  
  986. # }}}
  987. # {{{ awk
  988.  
  989. alias -g A='| awk '
  990. alias -g A1="| awk '{print \$1}'"
  991. alias -g A2="| awk '{print \$2}'"
  992. alias -g A3="| awk '{print \$3}'"
  993. alias -g A4="| awk '{print \$4}'"
  994. alias -g A5="| awk '{print \$5}'"
  995. alias -g A6="| awk '{print \$6}'"
  996. alias -g A7="| awk '{print \$7}'"
  997. alias -g A8="| awk '{print \$8}'"
  998. alias -g A9="| awk '{print \$9}'"
  999. alias -g EA='|& awk '
  1000. alias -g EA1="|& awk '{print \$1}'"
  1001. alias -g EA2="|& awk '{print \$2}'"
  1002. alias -g EA3="|& awk '{print \$3}'"
  1003. alias -g EA4="|& awk '{print \$4}'"
  1004. alias -g EA5="|& awk '{print \$5}'"
  1005. alias -g EA6="|& awk '{print \$6}'"
  1006. alias -g EA7="|& awk '{print \$7}'"
  1007. alias -g EA8="|& awk '{print \$8}'"
  1008. alias -g EA9="|& awk '{print \$9}'"
  1009.  
  1010. # }}}
  1011.  
  1012. # }}}
  1013.  
  1014. # }}}
  1015. # {{{ Key bindings
  1016.  
  1017. sh_load_status 'key bindings'
  1018.  
  1019. bindkey -s '^X^Z' '%-^M'
  1020. bindkey -s '^[H' ' --help'
  1021. bindkey -s '^[V' ' --version'
  1022. bindkey '^[e' expand-cmd-path
  1023. #bindkey -s '^X?' '\eb=\ef\C-x*'
  1024. bindkey '^[^I'   reverse-menu-complete
  1025. bindkey '^X^N'   accept-and-infer-next-history
  1026. bindkey '^[p'    history-beginning-search-backward
  1027. bindkey '^[n'    history-beginning-search-forward
  1028. bindkey '^[P'    history-beginning-search-backward
  1029. bindkey '^[N'    history-beginning-search-forward
  1030. bindkey '^w'     kill-region-or-backward-word
  1031. bindkey '^[^W'   kill-region-or-backward-big-word
  1032. bindkey '^[T'    transpose-big-words
  1033. bindkey '^I'     complete-word
  1034. bindkey '^Xi'    incremental-complete-word
  1035. bindkey '^F'     magic-forward-char
  1036. # bindkey '^[b'    emacs-backward-word
  1037. # bindkey '^[f'    emacs-forward-word
  1038. bindkey '^[f'    magic-forward-word
  1039. bindkey '^[B'    backward-to-space
  1040. bindkey '^[F'    forward-to-space
  1041. bindkey '^[^b'   backward-to-/
  1042. bindkey '^[^f'   forward-to-/
  1043. bindkey '^[^[[C' emacs-forward-word
  1044. bindkey '^[^[[D' emacs-backward-word
  1045.  
  1046. bindkey '^[D'  kill-big-word
  1047.  
  1048. if zmodload zsh/deltochar >&/dev/null; then
  1049.  bindkey '^[z' zap-to-char
  1050.  bindkey '^[Z' delete-to-char
  1051. fi
  1052.  
  1053. # Fix weird sequence that rxvt produces
  1054. bindkey -s '^[[Z' '\t'
  1055.  
  1056. alias no=ls  # for Dvorak
  1057.  
  1058. # }}}
  1059. # {{{ Miscellaneous
  1060.  
  1061. sh_load_status 'miscellaneous'
  1062.  
  1063. # {{{ ls colours
  1064.  
  1065. if which dircolors >&/dev/null && [[ -e "${zdotdir}/.dircolors" ]]; then
  1066.  eval "`dircolors -b $zdotdir/.dircolors`"
  1067. fi
  1068.  
  1069. if [[ $ZSH_VERSION > 3.1.5 ]]; then
  1070.   zmodload -i zsh/complist
  1071.  
  1072.   zstyle ':completion:*' list-colors ''
  1073.  
  1074.   zstyle ':completion:*:*:*:*:processes' list-colors \
  1075.     '=(#b) #([0-9]#)*=0=01;31'
  1076.  
  1077.   # completion colours
  1078.   zstyle ':completion:*' list-colors "$LS_COLORS"
  1079. fi  
  1080.  
  1081. # }}}
  1082. # {{{ Don't always autologout
  1083.  
  1084. if [[ "${TERM}" == ([Ex]term*|rxvt*|dtterm|screen*) ]]; then
  1085.   unset TMOUT
  1086. fi
  1087.  
  1088. # }}}
  1089.  
  1090. # }}}
  1091.  
  1092. # {{{ Specific to local setups
  1093.  
  1094. sh_load_status 'local hooks'
  1095. run_hooks .zshrc.d
  1096.  
  1097. # }}}
  1098.  
  1099. # {{{ Clear up after status display
  1100.  
  1101. if [[ $TERM == tgtelnet ]]; then
  1102.   echo
  1103. else
  1104.   echo -n "\r"
  1105. fi
  1106.  
  1107. # }}}
  1108. # {{{ Profile report
  1109.  
  1110. if [[ -n "$ZSH_PROFILE_RC" ]]; then
  1111.   zprof >! ~/zshrc.zprof
  1112.   exit
  1113. fi
  1114.  
  1115. # }}}
  1116.  
  1117. # {{{ Search for history loosing bug
  1118.  
  1119. which check_hist_size >&/dev/null && check_hist_size
  1120.  
  1121. # }}}
Advertisement
Add Comment
Please, Sign In to add comment