-
Notifications
You must be signed in to change notification settings - Fork 5
/
zhiyin.zsh-theme
150 lines (132 loc) · 3.33 KB
/
zhiyin.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
# Clean, simple, compatible and meaningful.
# Tested on Linux, Unix and Windows under ANSI colors.
# It is recommended to use with a dark background.
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
#
# Mar 2013 Yad Smood
# VCS
YS_VCS_PROMPT_PREFIX1=" %{$fg[white]%}on%{$reset_color%} "
YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}"
YS_VCS_PROMPT_SUFFIX="%{$reset_color%}"
YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x"
YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o"
# Git info
local git_info='$(git_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}"
ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
# HG info
local hg_info='$(ys_hg_prompt_info)'
ys_hg_prompt_info() {
# make sure this is a hg dir
if [ -d '.hg' ]; then
echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}"
echo -n $(hg branch 2>/dev/null)
if [ -n "$(hg status 2>/dev/null)" ]; then
echo -n "$YS_VCS_PROMPT_DIRTY"
else
echo -n "$YS_VCS_PROMPT_CLEAN"
fi
echo -n "$YS_VCS_PROMPT_SUFFIX"
fi
}
local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})"
# Prompt format:
#
# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE
# $ COMMAND
#
# For example:
#
# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x [21:47:42] C:0
# $
PROMPT="
%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
%{$fg[white]%}@ \
%{$fg[green]%}%m \
%{$fg[white]%}in \
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
${hg_info}\
${git_info}\
\
%{$fg[white]%}[%*] $exit_code
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
psanimate_stop() {
touch /tmp/psanimatepid-$$
PID=`cat /tmp/psanimatepid-$$`
if [[ ! -z "$PID" ]]
then
(kill $PID > /dev/null 2>&1)
fi
rm /tmp/psanimatepid-$$
return 0
}
psanimate() {
SLEEP_TIMER=${1:-'1'}
psanimate_stop
_ps_emoji_animation() {
counter=0
increment=true
S="\033[s"
U="\033[u"
while [ : ]
do
hex=$(printf "%02X" $counter)
Zhiyin="\uE9${hex}"
POS="\033[1000D"
eval echo -ne '$S$POS$Zhiyin $U'
# Update the counter and check the bounds
if $increment; then
((counter++))
if [ $counter -eq 17 ]; then
increment=false
((counter--))
fi
else
((counter--))
if [ $counter -eq -1 ]; then
increment=true
((counter++))
fi
fi
sleep $SLEEP_TIMER
done
}
(_ps_emoji_animation & ; echo "$!" > /tmp/psanimatepid-$$)
return 0
}
function pscleanup {
echo "Cleaning the animation stuff"
psanimate_stop
unset PS_TASK_OVER
}
trap pscleanup EXIT
# 切换动画状态
function toggle_psanimate_state() {
if [[ $PS_ANIMATION_ENABLED == "true" ]]; then
psanimate_stop
export PS_ANIMATION_ENABLED="false"
else
psanimate 0.08
export PS_ANIMATION_ENABLED="true"
fi
}
# 设置 zsh 的 preexec 和 precmd 钩子
autoload -Uz add-zsh-hook
# 在执行命令之前停止动画
preexec() {
if [[ $PS_ANIMATION_ENABLED == "true" ]]; then
psanimate_stop
fi
}
# 在命令完成后重新启动动画
precmd() {
if [[ $PS_ANIMATION_ENABLED == "true" ]]; then
psanimate 0.08
fi
}
add-zsh-hook -Uz preexec preexec
add-zsh-hook -Uz precmd precmd
export PS_ANIMATION_ENABLED="true"