1
2
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
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
67
68 umask u=rwx,g=,o=
69
70
71 limit coredumpsize 10M
72
73
74
75
76
77 autoload colors && colors
78 autoload select-word-style zmv zcalc
79
80
81
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
89
90 autoload -U compinit && compinit
91 compdef _man w3mman
92 compdef _ssh ssh2
93
94 zstyle ':completion:*::::' completer _expand _complete _ignored
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
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
114
115
116
117
118
119
120
121 export PROMPT="%{%(!.$croot.$coff)%}»%{$coff%} "
122
123 export RPROMPT="%(1j.[%{$cjobs%}%j%{$coff%}].)%(?..[%{$cerror%}%?%{$coff%}])"
124
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
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
155
156
157 zle -N select-word-style
158 select-word-style bash
159 bindkey -e
160
161 bindkey ' ' magic-space
162 bindkey '[D' emacs-backward-word
163 bindkey '[C' emacs-forward-word
164 bindkey '^]' vi-match-bracket
165 bindkey '^[[8~' end-of-line
166 bindkey '^[[7~' beginning-of-line
167 bindkey '^k' kill-line
168
169
170
171
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
185 setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }
186
187
188
189
190
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
205 display_info
206
207