get rid of some random pub key stuck there
[home/.git] / .zshrc
1 5~PATH=~/bin${PATH:+:}$PATH
2
3 SAVEHIST=5000
4 HISTSIZE=8000
5 HISTFILE=~/.zshhistory
6 setopt SHARE_HISTORY
7 setopt EXTENDED_HISTORY
8 setopt HIST_EXPIRE_DUPS_FIRST
9 #setopt HIST_FIND_NO_DUPS
10 setopt HIST_REDUCE_BLANKS
11 setopt PUSHD_IGNORE_DUPS
12
13 autoload -U colors; colors
14
15 typeset -A title
16 title[start]="\e]0;"
17 title[end]="\a"
18
19
20 if [[ $TERM == (xterm|screen)* && $oldterm != $TERM$WINDOWID ]]; then
21         SHLVL=1
22         export oldterm=$TERM$WINDOWID
23 fi
24
25 REPORTTIME=1
26 TIMEFMT="%E=%U+%S"
27
28 #PS1="%(?..%{${fg_bold[red]}%}%?%{$reset_color%} )%(2L.%{${fg_bold[yellow]}%}<%L>%{$reset_color%} .)%B%(#.%{${bg[red]}%}.)%m %(#..%{$fg[green]%})%#%{$reset_color%}%b "
29 #RPS1=" %{${fg_bold[green]}%}%~%{${fg_bold[black]}%}|%{${fg_bold[blue]}%}%(t.DING!.%*)%{$reset_color%}"
30
31 setopt PROMPT_PERCENT
32 # Substitute vars.  Notice that we're in "", so $vars here are
33 # replaced already here.  All dynamic content needs to go
34 # in escaped \$vars.
35 #setopt PROMPT_SUBST
36 function prompt_generate {
37         PS1=""
38         # time
39         prompt_time
40         # switch to red background when root
41         #PS1="$PS1%(#.%{${bg[red]}%}.)"
42         # hostname
43         PS1="$PS1%B%m%b:"
44         # path
45         PS1="$PS1%{${fg_bold[black]}%}%~%b "
46         # git dynamic content, i.e. branch name
47         prompt_git
48         # history number
49         #PS1="$PS1%{${fg[magenta]}%}!%!$reset_color "
50         # jobs display
51         prompt_jobs
52         # shell nesting
53         PS1="$PS1%(2L.%{${fg_bold[yellow]}%}<%L>%{$reset_color%} .)"
54         # tty name
55         #PS1="$PS1%l "
56         # start second line
57         PS1="$PS1
58 "
59         # If we're in paste mode, forget all the fancyness and only do
60         # the basic prompt.
61         if [[ -n $paste_mode ]] {
62                 PS1=""
63         }
64         # return value
65         PS1="$PS1%(?..%{${fg_bold[red]}%}%?%{$reset_color%} )"
66         # prompt!
67         PS1="$PS1%(#.%{${bg[white]%}%B.%{$fg[green]%})%# %{$reset_color%}"
68 }
69
70 typeset -g lastding
71 function prompt_time {
72         local t
73         local -a curtime
74         local hour
75         local minute
76
77         curtime=(${(@s,:,)$(print -Pn "%D{%H:%M}")})
78         hour=$curtime[0]
79         minute=$curtime[2]
80
81         t="%*"
82         if [[ $minute -eq 0 && $lastding -ne $hour ]]; then
83                 lastding=$hour
84                 # not using ^G here, because then cat'ing
85                 # this file will beep.
86                 t="DING!$(printf '\a')   "
87         fi
88         PS1="$PS1%{${fg_bold[blue]}%}$t%{$reset_color%} "
89 }
90
91 function prompt_git {
92         local ref
93
94         ref=$(git symbolic-ref HEAD 2>/dev/null)
95         ref=${ref#refs/heads/}
96         if [[ -n $ref ]] {
97                 # real symbolic ref
98                 PS1="$PS1%{${fg[cyan]}%}$ref%{$reset_color%} "
99                 return
100         }
101
102         # maybe detached?
103         ref=$(git rev-parse HEAD 2>/dev/null)
104         ref=${ref[0,10]}
105         if [[ -n $ref ]] {
106                 # detached head, print commitid
107                 PS1="$PS1%{${bg[cyan]}${fg[black]}%}$ref%{$reset_color%} "
108                 return
109         }
110 }
111
112 function prompt_jobs {
113         # from http://www.miek.nl/blog/archives/2008/02/20/my_zsh_prompt_setup/index.html
114         local js
115         local jobno
116
117         js=()
118         for jobno (${(k)jobstates}) {
119                 local fullstate=$jobstates[$jobno]
120                 local state="${${(@s,:,)fullstate}[2]}"
121                 js+=($jobno${state//[^+-]/})
122         }
123         if [[ $#js -gt 0 ]]; then
124                 PS1="$PS1%{${fg[yellow]}%}[${(j:,:)js}]%{$reset_color%} "
125         fi
126 }
127
128 function precmd {
129         title_generate
130         prompt_generate
131 }
132
133 function title_generate {}
134
135 if [[ $TERM == (xterm|screen)* ]]; then
136         function title_generate {
137                 print -Pn "${title[start]}%n@%m:%~${title[end]}"
138         }
139
140         function preexec {
141                 emulate -L zsh
142                 local -a cmd; cmd=(${(z)1})
143                 local -a checkjobs
144
145                 case $cmd[1] in
146                 fg|wait)
147                         if (( $#cmd == 1 ))
148                         then
149                                 checkjobs=%+
150                         else
151                                 checkjobs=$cmd[2]
152                         fi
153                         ;;
154                 %*)
155                         checkjobs=$cmd[1]
156                         ;;
157                 esac
158
159                 print -n "${title[start]}"
160
161                 if [[ -n "$checkjobs" ]]
162                 then
163                         # from: http://www.zsh.org/mla/workers/2000/msg03990.html
164                         local -A jt; jt=(${(kv)jobtexts})       # Copy jobtexts for subshell
165                         builtin jobs -l $checkjobs 2>/dev/null >>(read num rest
166                                 cmd=(${(z)${(e):-\$jt$num}})
167                                 print -nr "$cmd")
168                 else
169                         print -nr "$cmd"
170                 fi
171
172                 print -Pn " | %* | "
173                 print -Pn "%n@%m:%~"
174                 print -n "${title[end]}"
175         }
176 fi
177
178 if which todo >/dev/null 2>&1; then
179         function chpwd {
180                 # only print stuff in the interactive case
181                 [[ ! -o interactive ]] && return
182
183                 todo
184         }
185 fi
186
187 if [[ -r ~/.aliasrc ]]; then
188         source ~/.aliasrc
189 fi
190
191 umask 22
192
193 if which vim >/dev/null 2>&1; then
194         export EDITOR=`which vim`
195 fi
196 export PAGER=less
197 export BLOCKSIZE=K
198 lesspipe=$(which lesspipe.sh 2>/dev/null) || \
199 lesspipe=$(which lesspipe 2>/dev/null)
200 if test -n "$lesspipe"; then
201         export LESSOPEN="|$lesspipe %s"
202 fi
203
204 if which keychain >/dev/null 2>&1; then
205         [ -f ~/.ssh/id_rsa ] && keychain -q id_rsa --nogui
206         [ -f ~/.ssh/id_dsa ] && keychain -q id_dsa --nogui
207         source ~/.keychain/$HOST-sh
208 fi
209
210 bindkey -e
211 bindkey '\e[H' beginning-of-line
212 bindkey '\e[F' end-of-line
213 bindkey '\eOH' beginning-of-line
214 bindkey '\eOF' end-of-line
215 bindkey '\e[1~' beginning-of-line
216 bindkey '\e[4~' end-of-line
217 autoload -U down-line-or-beginning-search
218 autoload -U up-line-or-beginning-search
219 zle -N down-line-or-beginning-search
220 zle -N up-line-or-beginning-search
221 bindkey '\e[B' down-line-or-beginning-search
222 bindkey '\e[A' up-line-or-beginning-search
223 autoload run-help
224 bindkey '\eOP' run-help
225 bindkey '\e[M' run-help
226 bindkey '\e[1;5D' backward-word
227 bindkey '\e[1;5C' forward-word
228 bindkey '\e[3~' delete-char
229 #WORDCHARS=${WORDCHARS//[\/&.;=]}
230 autoload -U select-word-style
231 select-word-style bash
232 zstyle ':zle:transpose-words' word-style shell
233 setopt NO_FLOW_CONTROL
234
235 autoload -U compinit; compinit
236
237 if [[ -r ~/.zshrc.local ]]; then
238         source ~/.zshrc.local
239 fi
240
241 cd .