-
Notifications
You must be signed in to change notification settings - Fork 1
/
pxq-style.zsh-theme
executable file
·452 lines (423 loc) · 9.9 KB
/
pxq-style.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# vim:ft=zsh ts=2 sw=2 sts=2
# agnoster's Theme - https://gist.github.com/3712874
### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts
CURRENT_BG='NONE'
case ${SOLARIZED_THEME:-dark} in
light) CURRENT_FG='white';;
*) CURRENT_FG='black';;
esac
# Special Powerline characters
# test () {
LC_ALL="" LC_CTYPE="zh_CN.UTF-8"
readonly SEGMENT_SEPARATOR="\ue0b0"
readonly SEGMENT_SEPARATOR_DIFF="\ue0b2"
readonly _color_front_set="%{"
readonly _color_back_set="%}"
# SEGMENT_SEPARATOR=$'\uf0da '
# SEGMENT_SEPARATOR_DIFF=$'\ue0be '
# }
__PROMPT=""
_echo(){
__PROMPT="$__PROMPT$1"
}
_color_reset="$_color_front_set\e[0m$_color_back_set"
# 使用%{%}防止终端颜色提示符被记入长度计量中影响补全的位置
set_terminal_fg(){
case $1 in
"reset")
_echo "$_color_front_set\e[39m$_color_back_set"
;;
"black")
set_terminal_fg 0
;;
"maroon")
set_terminal_fg 1
;;
"green")
set_terminal_fg 2
;;
"olive")
set_terminal_fg 3
;;
"navy")
set_terminal_fg 4
;;
"purple")
set_terminal_fg 5
;;
"teal")
set_terminal_fg 6
;;
"silver")
set_terminal_fg 7
;;
"grey")
set_terminal_fg 8
;;
"red")
set_terminal_fg 9
;;
"lime")
set_terminal_fg 10
;;
"yellow")
set_terminal_fg 11
;;
"blue")
set_terminal_fg 12
;;
"fuchisa")
set_terminal_fg 13
;;
"aqua")
set_terminal_fg 14
;;
"white")
set_terminal_fg 15
;;
"")
;;
"NONE")
;;
"cyan")
set_terminal_fg 51
;;
*)
color="$_color_front_set\e[38;5;$1m$_color_back_set"
_echo $color
;;
esac
}
set_terminal_bg(){
case $1 in
"reset")
_echo "$_color_front_set\e[49m$_color_back_set"
;;
"black")
set_terminal_bg 0
;;
"maroon")
set_terminal_bg 1
;;
"green")
set_terminal_bg 2
;;
"olive")
set_terminal_bg 3
;;
"navy")
set_terminal_bg 4
;;
"purple")
set_terminal_bg 5
;;
"teal")
set_terminal_bg 6
;;
"silver")
set_terminal_bg 7
;;
"grey")
set_terminal_bg 8
;;
"red")
set_terminal_bg 9
;;
"lime")
set_terminal_bg 10
;;
"yellow")
set_terminal_bg 11
;;
"blue")
set_terminal_bg 12
;;
"fuchisa")
set_terminal_bg 13
;;
"aqua")
set_terminal_bg 14
;;
"white")
set_terminal_bg 15
;;
"")
;;
"NONE")
;;
"cyan")
set_terminal_bg 51
;;
*)
color="$_color_front_set\e[48;5;$1m$_color_back_set"
_echo $color
;;
esac
}
# 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="$1" || bg=""
[[ -n $2 ]] && fg="$2" || fg=""
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
set_terminal_bg $bg
set_terminal_fg $CURRENT_BG
_echo $SEGMENT_SEPARATOR
elif [[ $CURRENT_BG != 'NONE' ]];then
set_terminal_bg $CURRENT_BG
set_terminal_fg 0
_echo ""
fi
if [[ $CURRENT_BG != 'NONE' ]];then
set_terminal_fg $2
set_terminal_bg $1
else
set_terminal_fg $2
set_terminal_bg $1
fi
CURRENT_BG=$1
[[ -n $3 ]] && _echo $3
}
prompt_segment_diff() {
_echo $_color_reset
local bg fg
set_terminal_bg $CURRENT_BG
set_terminal_fg $1
_echo $SEGMENT_SEPARATOR_DIFF
set_terminal_bg $1
set_terminal_fg $2
# _echo "$_color_front_set$(set_terminal_bg $CURRENT_BG)$_color_back_set$_color_front_set$(set_terminal_fg $1)$_color_back_set$SEGMENT_SEPARATOR_DIFF"
# _echo "$_color_front_set$(set_terminal_fg $2)$_color_back_set$_color_front_set$(set_terminal_bg $1)$_color_back_set"
CURRENT_BG=$1
# _echo "$_color_front_set\e[1m$_color_back_set"
[[ -n $3 ]] && _echo $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
set_terminal_bg reset
set_terminal_fg $CURRENT_BG
_echo $SEGMENT_SEPARATOR
set_terminal_fg reset
else
set_terminal_bg reset
set_terminal_fg reset
fi
CURRENT_BG='NONE'
}
### 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)
prompt_context() {
if [[ $USER == "root" ]];then
prompt_segment red white "$USER"
else
prompt_segment 4 white "$USER"
fi
if [[ -n "$SSH_CLIENT" ]];then
prompt_segment yellow red "直$HOSTNAME"
elif [ ${HOSTNAME:0:3} != "pxq" ];then
prompt_segment black white "$HOSTNAME"
fi
}
# Git: branch/detached head, dirty status
prompt_git() {
if ( which gitstatus_query > /dev/null );then
gitstatus_query next
if [ $VCS_STATUS_RESULT = "ok-sync" ];then
GIT_PRO=${${VCS_STATUS_LOCAL_BRANCH:-@$(print ${VCS_STATUS_COMMIT} | cut -c 1-8)}//\%/%%}
if [ "$VCS_STATUS_LOCAL_BRANCH" = "master" ] ;then
GIT_PRO="$(set_terminal_fg red)$VCS_STATUS_LOCAL_BRANCH$(set_terminal_fg white)"
fi
# with conflicted
if (( $VCS_STATUS_NUM_CONFLICTED > 0));then
GIT_PRO="$GIT_PRO $(set_terminal_fg red)$VCS_STATUS_NUM_CONFLICTED$(set_terminal_fg white)"
fi
# has commit
if (( $VCS_STATUS_NUM_STAGED > 0));then
GIT_PRO="$GIT_PRO +$VCS_STATUS_NUM_STAGED"
fi
# need commit
if (( $VCS_STATUS_NUM_UNSTAGED > 0));then
GIT_PRO="$GIT_PRO *$VCS_STATUS_NUM_UNSTAGED"
fi
# need push
if (( $VCS_STATUS_COMMITS_AHEAD > 0));then
GIT_PRO="$GIT_PRO ↑$VCS_STATUS_COMMITS_AHEAD"
fi
# need pull
if (( $VCS_STATUS_COMMITS_BEHIND > 0));then
GIT_PRO="$GIT_PRO ↓$VCS_STATUS_COMMITS_BEHIND"
fi
if (( $VCS_STATUS_NUM_CONFLICTED > 0));then
prompt_segment purple white "$GIT_PRO"
elif (( $VCS_STATUS_NUM_UNSTAGED > 0 || $VCS_STATUS_NUM_STAGED > 0 ));then
prompt_segment 136 white "$GIT_PRO"
else
prompt_segment green white "$GIT_PRO"
fi
fi
fi
}
# Dir: current working directory
prompt_dir() {
local local_path=${PWD:1}
if [ $MY_SHELL = "zsh" ];then
prompt_segment blue white ${local_path//'\/'/"$_color_front_set\e[38;5;0m$_color_back_set $_color_front_set\e[38;5;15m$_color_back_set "}
else
prompt_segment blue white "$(print -n ${local_path//"/"/" $_color_front_set\e[38;5;0m$_color_back_set$_color_front_set\e[38;5;15m$_color_back_set "})"
fi
}
prompt_shell(){
if [ -n $MY_SHELL ];then
prompt_segment cyan 0 "$MY_SHELL"
fi
}
# Virtualenv: current working virtualenv
prompt_virtualenv() {
local virtualenv_path="$VIRTUAL_ENV"
if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
prompt_segment blue black "(`basename $virtualenv_path`)"
fi
}
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_background_jobs() {
local -a symbols
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols="⚙ $(jobs -l | wc -l)" && prompt_segment_diff maroon cyan "$symbols"
}
prompt_last_command_status(){
if [[ $RETVAL -ne 0 ]] ;then
prompt_segment white red "菜"
prompt_segment red white "$RETVAL"
fi
}
prompt_show_now_time(){
prompt_segment blue white "$(date +"%T")"
}
if [ "$(uname -s)" = "Linux" ];then
for f in $(ls /sys/class/power_supply/);do
if [ -e /sys/class/power_supply/$f/online ];then
ACF="/sys/class/power_supply/$f/online"
fi
done
elif [ "$(uname -s)" = "Darwin" ];then
fi
prompt_bettery(){
if [ -d /sys/class/power_supply/BAT0 ];then
num="$(cat /sys/class/power_supply/BAT0/capacity)"
STATUS=$num
if [[ $num -lt 10 ]];then
prompt_segment_diff red white
else
if [[ $num -gt 90 ]];then
prompt_segment_diff green white
else
prompt_segment_diff olive white
fi
fi
if [ $( cat $ACF) -eq "1" ];then
if [[ $num -ne "100" ]];then
_echo ""
fi
else
set_terminal_fg red
_echo ""
set_terminal_fg white
fi
_echo " $num%%"
elif [ "$(uname -s)" = "Darwin" ];then
STATUS="$(pmset -g ps|grep -o '[0-9]*%')"
num=${STATUS%%%}
if [[ $num -lt 10 ]];then
prompt_segment_diff red white
else
if [[ $num -gt 90 ]];then
prompt_segment_diff green white
else
prompt_segment_diff olive white
fi
fi
if [[ $num -ne "100" ]];then
_echo ""
else
set_terminal_fg red
_echo ""
set_terminal_fg white
fi
_echo " $num%%"
fi
}
prompt_session_check(){
if [ -f .Session.vim ];then
prompt_segment green white " "
fi
if [ -f .vscode/settings.json ];then
prompt_segment 17 white " "
fi
if [ -f go.mod ]; then
prompt_segment teal white "ﳑ"
fi
if [ -f Cargo.toml ];then
prompt_segment 3 0 " "
fi
}
prompt_proxy(){
if [ $http_proxy ];then
prompt_segment black blue " "
fi
}
## Main prompt
build_prompt() {
RETVAL=$?
__PROMPT=""
_echo $_color_reset
prompt_virtualenv
prompt_context
if [ $MY_SHELL != "zsh" ];then
prompt_shell
fi
prompt_dir
if [ $MY_SHELL = "zsh" ];then
prompt_git
fi
prompt_session_check
prompt_proxy
prompt_end
_echo '\n'
prompt_show_now_time
prompt_last_command_status
prompt_end
_echo $_color_reset
echo -ne $__PROMPT
}
build_prompt_diff(){
__PROMPT=""
_echo $_color_reset
prompt_bettery
prompt_background_jobs
_echo $_color_reset
echo -n $__PROMPT
}
# if [ $MY_SHELL = "zsh" ];then
PS1='$(build_prompt) > '
RPROMPT='$(build_prompt_diff)'
# else
# PS1='$(echo -ne $(echo -n $(build_prompt))) > '
# fi
set_terminal_fg blue
_echo "["
set_terminal_fg green
_echo $(date -u +"%F")
set_terminal_fg blue
_echo ":"
set_terminal_fg green
_echo $(date -u +"%T")
set_terminal_fg blue
_echo "]"
print -P $__PROMPT