-
Notifications
You must be signed in to change notification settings - Fork 0
/
rzh.zsh-theme
executable file
·421 lines (376 loc) · 10.8 KB
/
rzh.zsh-theme
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
VIRTUAL_ENV_DISABLE_PROMPT=true
# PROMPT
if [ ! -n "${CUSTOMTHEME_PROMPT_CHAR+1}" ]; then
CUSTOMTHEME_PROMPT_CHAR="\$"
fi
if [ ! -n "${CUSTOMTHEME_PROMPT_ROOT+1}" ]; then
CUSTOMTHEME_PROMPT_ROOT=true
fi
# STATUS
if [ ! -n "${CUSTOMTHEME_STATUS_SHOW+1}" ]; then
CUSTOMTHEME_STATUS_SHOW=true
fi
if [ ! -n "${CUSTOMTHEME_STATUS_EXIT_SHOW+1}" ]; then
CUSTOMTHEME_STATUS_EXIT_SHOW=false
fi
if [ ! -n "${CUSTOMTHEME_STATUS_BG+1}" ]; then
CUSTOMTHEME_STATUS_BG=green
fi
if [ ! -n "${CUSTOMTHEME_STATUS_ERROR_BG+1}" ]; then
CUSTOMTHEME_STATUS_ERROR_BG=black
fi
if [ ! -n "${CUSTOMTHEME_STATUS_FG+1}" ]; then
CUSTOMTHEME_STATUS_FG=white
fi
# TIME
if [ ! -n "${CUSTOMTHEME_TIME_SHOW+1}" ]; then
CUSTOMTHEME_TIME_SHOW=true
fi
if [ ! -n "${CUSTOMTHEME_TIME_BG+1}" ]; then
CUSTOMTHEME_TIME_BG=black
fi
if [ ! -n "${CUSTOMTHEME_TIME_FG+1}" ]; then
CUSTOMTHEME_TIME_FG=cyan
fi
# VIRTUALENV
if [ ! -n "${CUSTOMTHEME_VIRTUALENV_SHOW+1}" ]; then
CUSTOMTHEME_VIRTUALENV_SHOW=true
fi
if [ ! -n "${CUSTOMTHEME_VIRTUALENV_BG+1}" ]; then
CUSTOMTHEME_VIRTUALENV_BG=yellow
fi
if [ ! -n "${CUSTOMTHEME_VIRTUALENV_FG+1}" ]; then
CUSTOMTHEME_VIRTUALENV_FG=white
fi
if [ ! -n "${CUSTOMTHEME_VIRTUALENV_PREFIX+1}" ]; then
CUSTOMTHEME_VIRTUALENV_PREFIX=🐍
fi
# NVM
if [ ! -n "${CUSTOMTHEME_NVM_SHOW+1}" ]; then
CUSTOMTHEME_NVM_SHOW=false
fi
if [ ! -n "${CUSTOMTHEME_NVM_BG+1}" ]; then
CUSTOMTHEME_NVM_BG=green
fi
if [ ! -n "${CUSTOMTHEME_NVM_FG+1}" ]; then
CUSTOMTHEME_NVM_FG=white
fi
if [ ! -n "${CUSTOMTHEME_NVM_PREFIX+1}" ]; then
CUSTOMTHEME_NVM_PREFIX="⬡ "
fi
# RVM
if [ ! -n "${CUSTOMTHEME_RVM_SHOW+1}" ]; then
CUSTOMTHEME_RVM_SHOW=true
fi
if [ ! -n "${CUSTOMTHEME_RVM_BG+1}" ]; then
CUSTOMTHEME_RVM_BG=magenta
fi
if [ ! -n "${CUSTOMTHEME_RVM_FG+1}" ]; then
CUSTOMTHEME_RVM_FG=white
fi
if [ ! -n "${CUSTOMTHEME_RVM_PREFIX+1}" ]; then
CUSTOMTHEME_RVM_PREFIX=♦️
fi
# DIR
if [ ! -n "${CUSTOMTHEME_DIR_SHOW+1}" ]; then
CUSTOMTHEME_DIR_SHOW=true
fi
if [ ! -n "${CUSTOMTHEME_DIR_BG+1}" ]; then
CUSTOMTHEME_DIR_BG=black
fi
if [ ! -n "${CUSTOMTHEME_DIR_FG+1}" ]; then
CUSTOMTHEME_DIR_FG=white
fi
if [ ! -n "${CUSTOMTHEME_DIR_CONTEXT_SHOW+1}" ]; then
CUSTOMTHEME_DIR_CONTEXT_SHOW=false
fi
if [ ! -n "${CUSTOMTHEME_DIR_EXTENDED+1}" ]; then
CUSTOMTHEME_DIR_EXTENDED=true
fi
# GIT
if [ ! -n "${CUSTOMTHEME_GIT_SHOW+1}" ]; then
CUSTOMTHEME_GIT_SHOW=true
fi
if [ ! -n "${CUSTOMTHEME_GIT_BG+1}" ]; then
CUSTOMTHEME_GIT_BG=black
fi
if [ ! -n "${CUSTOMTHEME_GIT_FG+1}" ]; then
CUSTOMTHEME_GIT_FG=red
fi
if [ ! -n "${CUSTOMTHEME_GIT_EXTENDED+1}" ]; then
CUSTOMTHEME_GIT_EXTENDED=true
fi
# CONTEXT
if [ ! -n "${CUSTOMTHEME_CONTEXT_SHOW+1}" ]; then
CUSTOMTHEME_CONTEXT_SHOW=false
fi
if [ ! -n "${CUSTOMTHEME_CONTEXT_BG+1}" ]; then
CUSTOMTHEME_CONTEXT_BG=black
fi
if [ ! -n "${CUSTOMTHEME_CONTEXT_FG+1}" ]; then
CUSTOMTHEME_CONTEXT_FG=default
fi
# GIT PROMPT
if [ ! -n "${CUSTOMTHEME_GIT_PREFIX+1}" ]; then
ZSH_THEME_GIT_PROMPT_PREFIX="[ "
else
ZSH_THEME_GIT_PROMPT_PREFIX=$CUSTOMTHEME_GIT_PREFIX
fi
if [ ! -n "${CUSTOMTHEME_GIT_SUFFIX+1}" ]; then
ZSH_THEME_GIT_PROMPT_SUFFIX=" ]"
else
#ZSH_THEME_GIT_PROMPT_SUFFIX=$CUSTOMTHEME_GIT_SUFFIX
fi
if [ ! -n "${CUSTOMTHEME_GIT_DIRTY+1}" ]; then
ZSH_THEME_GIT_PROMPT_DIRTY=" 💉 "
else
ZSH_THEME_GIT_PROMPT_DIRTY=$CUSTOMTHEME_GIT_DIRTY
fi
if [ ! -n "${CUSTOMTHEME_GIT_CLEAN+1}" ]; then
ZSH_THEME_GIT_PROMPT_CLEAN=" 🍑"
else
ZSH_THEME_GIT_PROMPT_CLEAN=$CUSTOMTHEME_GIT_CLEAN
fi
if [ ! -n "${CUSTOMTHEME_GIT_ADDED+1}" ]; then
ZSH_THEME_GIT_PROMPT_ADDED=" 🗿"
else
ZSH_THEME_GIT_PROMPT_ADDED=$CUSTOMTHEME_GIT_ADDED
fi
if [ ! -n "${CUSTOMTHEME_GIT_MODIFIED+1}" ]; then
ZSH_THEME_GIT_PROMPT_MODIFIED=" 🚨"
else
ZSH_THEME_GIT_PROMPT_MODIFIED=$CUSTOMTHEME_GIT_MODIFIED
fi
if [ ! -n "${CUSTOMTHEME_GIT_DELETED+1}" ]; then
ZSH_THEME_GIT_PROMPT_DELETED=" 💀"
else
ZSH_THEME_GIT_PROMPT_DELETED=$CUSTOMTHEME_GIT_DELETED
fi
if [ ! -n "${CUSTOMTHEME_GIT_UNTRACKED+1}" ]; then
ZSH_THEME_GIT_PROMPT_UNTRACKED=" 🔋"
else
ZSH_THEME_GIT_PROMPT_UNTRACKED=$CUSTOMTHEME_GIT_UNTRACKED
fi
if [ ! -n "${CUSTOMTHEME_GIT_RENAMED+1}" ]; then
ZSH_THEME_GIT_PROMPT_RENAMED=" 😼"
else
ZSH_THEME_GIT_PROMPT_RENAMED=$CUSTOMTHEME_GIT_RENAMED
fi
if [ ! -n "${CUSTOMTHEME_GIT_UNMERGED+1}" ]; then
ZSH_THEME_GIT_PROMPT_UNMERGED=" 😿"
else
ZSH_THEME_GIT_PROMPT_UNMERGED=$CUSTOMTHEME_GIT_UNMERGED
fi
if [ ! -n "${CUSTOMTHEME_GIT_AHEAD+1}" ]; then
ZSH_THEME_GIT_PROMPT_AHEAD=" 🌝"
else
ZSH_THEME_GIT_PROMPT_AHEAD=$CUSTOMTHEME_GIT_AHEAD
fi
if [ ! -n "${CUSTOMTHEME_GIT_BEHIND+1}" ]; then
ZSH_THEME_GIT_PROMPT_BEHIND=" 🌚"
else
ZSH_THEME_GIT_PROMPT_BEHIND=$CUSTOMTHEME_GIT_BEHIND
fi
if [ ! -n "${CUSTOMTHEME_GIT_DIVERGED+1}" ]; then
ZSH_THEME_GIT_PROMPT_DIVERGED=" 😾"
else
ZSH_THEME_GIT_PROMPT_DIVERGED=$CUSTOMTHEME_GIT_PROMPT_DIVERGED
fi
# ------------------------------------------------------------------------------
# SEGMENT DRAWING
# A few functions to make it easy and re-usable to draw segmented prompts
# ------------------------------------------------------------------------------
CURRENT_BG='NONE'
SEGMENT_SEPARATOR=''
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
# ------------------------------------------------------------------------------
# PROMPT COMPONENTS
# Each component will draw itself, and hide itself if no information needs
# to be shown
# ------------------------------------------------------------------------------
# Context: user@hostname (who am I and where am I)
context() {
local user="$(whoami)"
[[ "$user" != "$CUSTOMTHEME_CONTEXT_DEFAULT_USER" || -n "$CUSTOMTHEME_IS_SSH_CLIENT" ]] && echo -n "${user}@%m"
}
prompt_context() {
[[ $CUSTOMTHEME_CONTEXT_SHOW == false ]] && return
local _context="$(context)"
[[ -n "$_context" ]] && prompt_segment $CUSTOMTHEME_CONTEXT_BG $CUSTOMTHEME_CONTEXT_FG "$_context"
}
# Git
prompt_git() {
if [[ $CUSTOMTHEME_GIT_SHOW == false ]] then
return
fi
local ref dirty mode repo_path
repo_path=$(git rev-parse --git-dir 2>/dev/null)
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
prompt_segment $CUSTOMTHEME_GIT_BG $CUSTOMTHEME_GIT_FG
if [[ $CUSTOMTHEME_GIT_EXTENDED == true ]] then
echo -n $(git_prompt_info)$(git_prompt_status)
else
echo -n $(git_prompt_info)
fi
fi
}
prompt_hg() {
local rev status
if $(hg id >/dev/null 2>&1); then
if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added
# prompt_segment red white
st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification
# prompt_segment yellow black
st='±'
else
# if working copy is clean
# prompt_segment green black
fi
echo -n $(hg prompt "☿ {rev}@{branch}") $st
else
st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null)
if $(hg st | grep -Eq "^\?"); then
# prompt_segment red black
st='±'
elif $(hg st | grep -Eq "^(M|A)"); then
# prompt_segment yellow black
st='±'
else
# prompt_segment green black
fi
echo -n "☿ $rev@$branch" $st
fi
fi
}
# Dir: current working directory
prompt_dir() {
if [[ $CUSTOMTHEME_DIR_SHOW == false ]] then
return
fi
local dir='😤 '
local _context="$(context)"
[[ $CUSTOMTHEME_DIR_CONTEXT_SHOW == true && -n "$_context" ]] && dir="${dir}${_context}:"
[[ $CUSTOMTHEME_DIR_EXTENDED == true ]] && dir="${dir}%4(c:...:)%3c" || dir="${dir}%1~"
prompt_segment $CUSTOMTHEME_DIR_BG $CUSTOMTHEME_DIR_FG $dir
}
# RVM: only shows RVM info if on a gemset that is not the default one
prompt_rvm() {
if [[ $CUSTOMTHEME_RVM_SHOW == false ]] then
return
fi
if which rvm-prompt &> /dev/null; then
if [[ ! -n $(rvm gemset list | grep "=> (default)") ]]
then
prompt_segment $CUSTOMTHEME_RVM_BG $CUSTOMTHEME_RVM_FG $CUSTOMTHEME_RVM_PREFIX" $(rvm-prompt i v g)"
fi
fi
}
# Virtualenv: current working virtualenv
prompt_virtualenv() {
if [[ $CUSTOMTHEME_VIRTUALENV_SHOW == false ]] then
return
fi
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment $CUSTOMTHEME_VIRTUALENV_BG $CUSTOMTHEME_VIRTUALENV_FG $CUSTOMTHEME_VIRTUALENV_PREFIX" $(basename $virtualenv_path)"
fi
}
# NVM: Node version manager
prompt_nvm() {
if [[ $CUSTOMTHEME_NVM_SHOW == false ]] then
return
fi
$(type nvm >/dev/null 2>&1) || return
local nvm_prompt
nvm_prompt=$(node -v 2>/dev/null)
[[ "${nvm_prompt}x" == "x" ]] && return
nvm_prompt=${nvm_prompt:1}
prompt_segment $CUSTOMTHEME_NVM_BG $CUSTOMTHEME_NVM_FG $CUSTOMTHEME_NVM_PREFIX$nvm_prompt
}
prompt_time() {
if [[ $CUSTOMTHEME_TIME_SHOW == false ]] then
return
fi
prompt_segment $CUSTOMTHEME_TIME_BG $CUSTOMTHEME_TIME_FG '🔫'
}
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
if [[ $CUSTOMTHEME_STATUS_SHOW == false ]] then
return
fi
local symbols
symbols=()
[[ $RETVAL -ne 0 && $CUSTOMTHEME_STATUS_EXIT_SHOW != true ]] && symbols+="😭"
[[ $RETVAL -ne 0 && $CUSTOMTHEME_STATUS_EXIT_SHOW == true ]] && symbols+="😭 $RETVAL"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡%f"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="⚙"
if [[ -n "$symbols" && $RETVAL -ne 0 ]] then
prompt_segment $CUSTOMTHEME_STATUS_ERROR_BG $CUSTOMTHEME_STATUS_FG "$symbols"
elif [[ -n "$symbols" ]] then
prompt_segment $CUSTOMTHEME_STATUS_BG $CUSTOMTHEME_STATUS_FG "$symbols"
fi
}
# Prompt Character
prompt_char() {
local bt_prompt_char
if [[ ${#CUSTOMTHEME_PROMPT_CHAR} -eq 1 ]] then
bt_prompt_char="👉 "
fi
if [[ $CUSTOMTHEME_PROMPT_ROOT == true ]] then
bt_prompt_char="%(!.%F{red}#.%F{green}${bt_prompt_char}%f)"
fi
echo -n $bt_prompt_char
}
# ------------------------------------------------------------------------------
# MAIN
# Entry point
# ------------------------------------------------------------------------------
build_prompt() {
RETVAL=$?
prompt_time
prompt_status
prompt_rvm
prompt_virtualenv
prompt_nvm
prompt_context
prompt_dir
prompt_git
# prompt_hg
prompt_end
}
PROMPT='
%{%f%b%k%}$(build_prompt)
%{${fg_bold[default]}%}$(prompt_char) %{$reset_color%}'