blob: 21fab1ee20404f619010193c35edebb99fd267cc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
# wunjo prompt theme
autoload -U zgitinit
zgitinit
autoload colors
colors
prompt_wunjo_help () {
cat <<'EOF'
prompt wunjo
EOF
}
# We want our vim users to be able to see what mode their in.
# From http://www.jukie.net/~bart/conf/zsh.d/S60_prompt
coloratom() {
local off=$1 atom=$2
if [[ $atom[1] == [[:upper:]] ]]; then
off=$(( $off + 60 ))
fi
echo $(( $off + $colorcode[${(L)atom}] ))
}
colorword() {
local fg=$1 bg=$2 att=$3
local -a s
if [ -n "$fg" ]; then
s+=$(coloratom 30 $fg)
fi
if [ -n "$bg" ]; then
s+=$(coloratom 40 $bg)
fi
if [ -n "$att" ]; then
s+=$attcode[$att]
fi
echo "%{"$'\e['${(j:;:)s}m"%}"
}
prompt_wunjo_setup() {
local verbose
if [[ $TERM == screen* ]] && [ -n "$STY" ]; then
# verbose=
# Set to 1 by Ryan... no clue why you wouldn't want it.
verbose=1
else
verbose=1
fi
typeset -A colorcode
colorcode[black]=0
colorcode[red]=1
colorcode[green]=2
colorcode[yellow]=3
colorcode[blue]=4
colorcode[magenta]=5
colorcode[cyan]=6
colorcode[white]=7
colorcode[default]=9
colorcode[k]=$colorcode[black]
colorcode[r]=$colorcode[red]
colorcode[g]=$colorcode[green]
colorcode[y]=$colorcode[yellow]
colorcode[b]=$colorcode[blue]
colorcode[m]=$colorcode[magenta]
colorcode[c]=$colorcode[cyan]
colorcode[w]=$colorcode[white]
colorcode[.]=$colorcode[default]
typeset -A attcode
attcode[none]=00
attcode[bold]=01
attcode[faint]=02
attcode[standout]=03
attcode[underline]=04
attcode[blink]=05
attcode[reverse]=07
attcode[conceal]=08
attcode[normal]=22
attcode[no-standout]=23
attcode[no-underline]=24
attcode[no-blink]=25
attcode[no-reverse]=27
attcode[no-conceal]=28
local -A pc
pc[default]='default'
pc[date]='cyan'
pc[time]='Blue'
pc[host]='ZSH_HOST_COLOUR'
pc[user]='cyan'
pc[punc]='yellow'
pc[line]='magenta'
pc[hist]='green'
pc[path]='Cyan'
pc[shortpath]='default'
pc[rc]='red'
pc[scm_branch]='Cyan'
pc[scm_commitid]='Yellow'
pc[scm_status_dirty]='Red'
pc[scm_status_staged]='Green'
pc[#]='Yellow'
pc[insert]='green'
pc[command]='red'
for cn in ${(k)pc}; do
pc[${cn}]=$(colorword $pc[$cn])
done
pc[reset]=$(colorword . . 00)
typeset -Ag wunjo_prompt_colors
wunjo_prompt_colors=(${(kv)pc})
local p_date p_line p_rc
p_date="$pc[date]%D{%Y-%m-%d} $pc[time]%D{%T}$pc[reset]"
p_line="$pc[line]%y$pc[reset]"
function zle-line-init zle-keymap-select {
VIMODE="${${KEYMAP/vicmd/C}/(main|viins)/I}"
VICOLOR="${${KEYMAP/vicmd/$fg[green]}/(main|viins)/$fg[red]}"
zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select
vi="${VICOLOR}${VIMODE}"
PROMPT=
if [ $verbose ]; then
PROMPT+="$pc[host]%m$pc[reset] "
fi
PROMPT+="$pc[path]%(2~.%~.%/)$pc[reset]"
PROMPT+="\$(prompt_wunjo_scm_status)"
PROMPT+="%(?.. $pc[rc]exited %1v$pc[reset])"
PROMPT+="
"
PROMPT+="$pc[hist]%h$pc[reset] "
PROMPT+="$pc[shortpath]%1~$pc[reset]"
PROMPT+="\$(prompt_wunjo_scm_branch)"
PROMPT+=" $vi"
PROMPT+=" $pc[#]%#$pc[reset] "
RPROMPT=
if [ $verbose ]; then
RPROMPT+="$p_date "
fi
RPROMPT+="$pc[user]%n$pc[reset]"
RPROMPT+=" $p_line"
export PROMPT RPROMPT
precmd_functions+='prompt_wunjo_precmd'
}
prompt_wunjo_precmd() {
local ex=$?
psvar=()
if [[ $ex -ge 128 ]]; then
sig=$signals[$ex-127]
psvar[1]="sig${(L)sig}"
else
psvar[1]="$ex"
fi
}
prompt_wunjo_scm_status() {
zgit_isgit || return
local -A pc
pc=(${(kv)wunjo_prompt_colors})
head=$(zgit_head)
gitcommit=$(git describe --always $head 2>/dev/null)
local -a commits
if zgit_rebaseinfo; then
orig_commit=$(git describe --always $zgit_info[rb_head])
orig_name=$(git name-rev --name-only $zgit_info[rb_head])
orig="$pc[scm_branch]$orig_name$pc[punc]($pc[scm_commitid]$orig_commit$pc[punc])"
onto_commit=$(git describe --always $zgit_info[rb_onto])
onto_name=$(git name-rev --name-only $zgit_info[rb_onto])
onto="$pc[scm_branch]$onto_name$pc[punc]($pc[scm_commitid]$onto_commit$pc[punc])"
if [ -n "$zgit_info[rb_upstream]" ] && [ $zgit_info[rb_upstream] != $zgit_info[rb_onto] ]; then
upstream_commit=$(git describe --always $zgit_info[rb_upstream])
upstream_name=$(git name-rev --name-only $zgit_info[rb_upstream])
upstream="$pc[scm_branch]$upstream_name$pc[punc]($pc[scm_commitid]$upstream_commit$pc[punc])"
commits+="rebasing $upstream$pc[reset]..$orig$pc[reset] onto $onto$pc[reset]"
else
commits+="rebasing $onto$pc[reset]..$orig$pc[reset]"
fi
local -a revs
revs=($(git rev-list $zgit_info[rb_onto]..HEAD))
if [ $#revs -gt 0 ]; then
commits+="\n$#revs commits in"
fi
if [ -f $zgit_info[dotest]/message ]; then
mess=$(head -n1 $zgit_info[dotest]/message)
commits+="on $mess"
fi
elif [ -n "$gitcommit" ]; then
commits+="on $pc[scm_branch]$head$pc[punc]($pc[scm_commitid]$gitcommit$pc[punc])$pc[reset]"
local track_merge=$(zgit_tracking_merge)
if [ -n "$track_merge" ]; then
if git rev-parse --verify -q $track_merge >/dev/null; then
local track_remote=$(zgit_tracking_remote)
local tracked=$(git describe --always $track_merge 2>/dev/null)
local -a revs
revs=($(git rev-list --reverse $track_merge..HEAD))
if [ $#revs -gt 0 ]; then
local base=$(git describe --always $revs[1]~1)
local base_name=$(git name-rev --name-only $base)
local base_short=$(git describe --always $base)
local word_commits
if [ $#revs -gt 1 ]; then
word_commits='commits'
else
word_commits='commit'
fi
local conj="since"
if [[ "$base" == "$tracked" ]]; then
conj+=" tracked"
tracked=
fi
commits+="$#revs $word_commits $conj $pc[scm_branch]$base_name$pc[punc]($pc[scm_commitid]$base_short$pc[punc])$pc[reset]"
fi
if [ -n "$tracked" ]; then
local track_name=$track_merge
if [[ $track_remote == "." ]]; then
track_name=${track_name##*/}
fi
tracked=$(git describe --always $tracked)
commits+="tracking $pc[scm_branch]$track_name$pc[punc]"
if [[ "$tracked" != "$gitcommit" ]]; then
commits[$#commits]+="($pc[scm_commitid]$tracked$pc[punc])"
fi
commits[$#commits]+="$pc[reset]"
fi
fi
fi
fi
gitsvn=$(git rev-parse --verify -q --short git-svn)
if [ $? -eq 0 ]; then
gitsvnrev=$(zgit_svnhead $gitsvn)
gitsvn=$(git describe --always $gitsvn)
if [ -n "$gitsvnrev" ]; then
local svninfo=''
local -a revs
svninfo+="$pc[default]svn$pc[punc]:$pc[scm_branch]r$gitsvnrev"
revs=($(git rev-list git-svn..HEAD))
if [ $#revs -gt 0 ]; then
svninfo+="$pc[punc]@$pc[default]HEAD~$#revs"
svninfo+="$pc[punc]($pc[scm_commitid]$gitsvn$pc[punc])"
fi
commits+=$svninfo
fi
fi
if [ $#commits -gt 0 ]; then
echo -n " ${(j: :)commits}"
fi
}
prompt_wunjo_scm_branch() {
zgit_isgit || return
local -A pc
pc=(${(kv)wunjo_prompt_colors})
echo -n "$pc[punc]:$pc[scm_branch]$(zgit_head)"
if zgit_inworktree; then
if ! zgit_isindexclean; then
echo -n "$pc[scm_status_staged]+"
fi
local -a dirty
if ! zgit_isworktreeclean; then
dirty+='!'
fi
if zgit_hasunmerged; then
dirty+='*'
fi
if zgit_hasuntracked; then
dirty+='?'
fi
if [ $#dirty -gt 0 ]; then
echo -n "$pc[scm_status_dirty]${(j::)dirty}"
fi
fi
echo $pc[reset]
}
prompt_wunjo_setup "$@"
# vim:set ft=zsh:
|