1  #------------------------------------------------------------------#--
  2  # my zsh-config ... coz zsh rox hell 
  3  #------------------------------------------------------------------#--
  4
  5
  6  : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
  7
  8  if [ -f ~/.ssh/known_hosts ]; then
  9    _ssh_known_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:# *}%%\ *}%%,*})
 10  else
 11    _ssh_known_hosts=()
 12  fi
 13
 14  if [ -f ~/.ssh/config ]; then
 15    _ssh_config=( $(sed -n '/\*/d;/^Host/p;' ~/.ssh/config | awk '{ print $2 }'))
 16  else
 17    _ssh_config=""
 18  fi
 19
 20  hosts=(
 21      "$_etc_hosts[@]"
 22      "$_ssh_known_hosts[@]"
 23      "$_ssh_config[@]"
 24      localhost
 25  )
 26
 27  typeset -U hosts
 28
 29  #--------------------------------------------------------#--
 30  # options
 31  #--------------------------------------------------------#--
 32  setopt \
 33      append_history \
 34      autocd \
 35      bang_hist \
 36      beep \
 37   no_bgnice \
 38      correct \
 39      extended_glob \
 40      extended_history \
 41      glob \
 42      glob_complete \
 43      glob_dots \
 44      hist_no_store \
 45      hist_save_no_dups \
 46      hist_ignore_space \
 47      hist_no_functions \
 48      hist_reduce_blanks \
 49   no_hup \
 50      ksh_glob \
 51      list_packed \
 52      long_list_jobs \
 53      mark_dirs \
 54      notify \
 55   no_prompt_cr \
 56      promptcr \
 57      share_history
 58
 59  HISTFILE=$HOME/.zhistory
 60  HISTSIZE=1000
 61  SAVEHIST=1000
 62  WATCH=all
 63  WATCHFMT='%n %a %l from %m at %t.'
 64  LOGCHECK=10
 65
 66  # umask is for permissions-of-new-files
 67  # i cant handle octals :) but its the same as 077
 68  umask u=rwx,g=,o=
 69
 70  # i am a developer, so i need cores :)
 71  limit coredumpsize 10M
 72
 73
 74  #--------------------------------------------------------#--
 75  # load zsh-kungfoo
 76  #--------------------------------------------------------#--
 77  autoload colors && colors
 78  autoload select-word-style zmv zcalc
 79
 80  # if you now paste a url it will be magically quoted!
 81  # but it only works on 4.2.0 and later.
 82  if [ ${ZSH_VERSION//\./} -ge 420 ]; then
 83    autoload -U url-quote-magic
 84    zle -N self-insert url-quote-magic
 85  fi
 86
 87  #--------------------------------------------------------#--
 88  # completion
 89  #--------------------------------------------------------#--
 90  autoload -U compinit && compinit
 91  compdef _man w3mman
 92  compdef _ssh ssh2
 93
 94  zstyle ':completion:*::::' completer _expand _complete _ignored #_approximate
 95  zstyle ':completion:*:expand:*' tag-order all-expansions
 96
 97  zstyle '*' hosts $hosts
 98
 99  zstyle ':completion:*:processes' command 'ps x -o pid,nice,pcpu,tt,args'
100  zstyle ':completion:*' list-colors $LS_COLORS
101
102  #--------------------------------------------------------#--
103  # prompt
104  #--------------------------------------------------------#--
105
106  coff=$reset_color
107  croot=$fg_bold[red]
108  cname=$fg_bold[green]
109  cjobs=$fg_bold[yellow]
110  cerror=$fg_bold[magenta]
111  chost=$fg_bold[cyan]
112
113  # a pretty complicated, 2line prompt with a lot of info
114  # i replaced it with a simpler one and get the info by calling "di"
115  #export PROMPT="z|%{%(!.$croot.$cname)%}%n%{$coff%}@%{$chost%}%m%{$coff%}\
116  # | %d | %T\
117  # | %(1j.[%{$cjobs%}%j%{$coff%}].)%(?..[%{$cerror%}%?%{$coff%}])
118  #» "
119
120  # thats the more simple prompt
121  export PROMPT="%{%(!.$croot.$coff)%}»%{$coff%} "
122  # display jobs and last error on the right side of the prompt
123  export RPROMPT="%(1j.[%{$cjobs%}%j%{$coff%}].)%(?..[%{$cerror%}%?%{$coff%}])"
124  # display info
125  display_info() {
126      if [ $UID != 0 ]; then
127          echo -n "${cname}$USER${coff}"
128      else
129          echo -n "${croot}$USER${coff}"
130      fi
131      echo "@${chost}$HOST${coff} | $PWD | `date +'%H:%M'` |"
132  }
133
134  alias di=display_info
135
136  # set infos to the *terms
137  chpwd() {
138      display_info
139      [[ -t 1 ]] || return
140      case "$TERM" in
141          *xterm*|*rxvt*) echo -en "\e]2;<$USER@$HOST>: $PWD\a";;
142          screen) [ -n $DISPLAY ] && echo -en "\e]2;<$USER@$HOST>: $PWD\a"
143          ;;
144      esac
145  }
146
147  case "$TERM" in
148    *xterm*|*rxvt*) echo -en "\e]2;<$USER@$HOST>: $PWD\a";;
149    screen) [ -n $DISPLAY ] && echo -en "\e]2;<$USER@$HOST>: $PWD\a";;
150  esac
151
152
153  #--------------------------------------------------------#--
154  # keymapping
155  #--------------------------------------------------------#--
156  # press ctrl-v to get special keys (like 'home')
157  zle -N select-word-style
158  select-word-style bash
159  bindkey -e
160  #bindkey '\e^h' delete-backward-word  # alt - backspace
161  bindkey ' ' magic-space              # history completion with space too
162  bindkey '[D' emacs-backward-word     # alt-cursor-left
163  bindkey '[C' emacs-forward-word      # alt-cursor-right
164  bindkey '^]' vi-match-bracket        # ctrl 5
165  bindkey '^[[8~' end-of-line          # home
166  bindkey '^[[7~' beginning-of-line    # end
167  bindkey '^k' kill-line
168  #  c-_ is undo
169
170  #----------------------------------------------------
171  # keychain => http://www.gentoo.org/projects/keychain
172  #----------------------------------------------------
173  if [ `whoami` != 'root' ]
174  then
175      if [ -f ~/.ssh/id_dsa -a -f ~/.ssh/id_dsa ]; then
176          if which keychain &> /dev/null
177          then
178              keychain -q id_dsa id_rsa
179              . ~/.keychain/${HOST}-sh
180          fi
181      fi
182  fi
183
184  # csh/tcsh style
185  setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }
186
187
188
189  #-----------------
190  # host-specifics
191  #-----------------
192
193  rcs=(
194    ~/.zshrc.aliases
195    ~/.zshrc.funcs
196    ~/.zshrc.local
197  )
198
199  for rc in $rcs ; do
200    [ -f $rc ] && source $rc
201  done
202  true
203
204  # now show the info
205  display_info
206
207  # vim:nowrap