-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpowerzeesh.zsh-theme
257 lines (154 loc) · 4.4 KB
/
powerzeesh.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
FG=black
SYMBOLS=()
# colors picked from 256 colors
color_prompt_name_fg=2
color_prompt_name_bg=0
color_prompt_root_fg=1
color_prompt_root_bg=0
color_prompt_dir_fg=6
color_prompt_dir_bg=7
color_prompt_dir_root_bg=8
color_prompt_dir_root_fg=11
color_prompt_git_red=1
color_prompt_git_green=2
color_prompt_git_blue=4
color_prompt_git_purple=5
color_prompt_git_cyan=6
color_prompt_white=7
color_prompt_git_grey=8
color_prompt_git_green=10
color_prompt_git_orange=11
# segments
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
print -n "%{$fg%}"
else
print -n "%{$fg%}"
fi
CURRENT_BG=$1
[[ -n $3 ]] && print -n $3
}
prompt_context () {
local user=`whoami`
if [[ -n "$SSH_CONNECTION" ]]; then
prompt_segment $color_prompt_name_bg $color_prompt_name_fg "%{%F{white}%}[SSH] %{%F{yellow}%}%{%F{$color_prompt_name_fg}%}${HOST}"
elif [[ $(id -u) -ne 0 ]]; then
prompt_segment $color_prompt_name_bg $color_prompt_name_fg "$"
else
if grep "Server" /etc/hostname > /dev/null || grep "wg" /etc/hostname > /dev/null; then
prompt_segment $color_prompt_root_bg $color_prompt_root_fg "# %{%F{white}%}[SSH] %{%F{$color_prompt_root_fg}%}${HOST}"
else
prompt_segment $color_prompt_root_bg $color_prompt_root_fg "#"
fi
fi
}
prompt_git () {
local color ref
is_dirty () {
test -n "$(git status --porcelain --ignore-submodules)"
}
commitsAhead () {
test -n "$(git_commits_ahead)"
}
ref="$vcs_info_msg_0_"
if [[ -n "$ref" ]]; then
if is_dirty; then
color=$color_prompt_git_red
ref="${ref} $PLUSMINUS"
elif commitsAhead; then
color=$color_prompt_git_orange
ref="${ref} $STAR"
else
color=$color_prompt_git_green
ref="${ref} "
fi
if [[ "${ref/.../}" == "$ref" ]]; then
ref="$BRANCH $ref"
else
ref="$DETACHED ${ref/.../}"
fi
prompt_segment $color $color " {$ref}"
fi
}
prompt_vpn () {
local OUTPUT=`pgrep -x openvpn`
if [[ $OUTPUT != "" ]]; then
prompt_segment $color_prompt_dir_bg $color_prompt_git_grey ' <VPN>'
fi
}
prompt_dir () {
prompt_segment $color_prompt_dir_bg $color_prompt_dir_fg ' %~'
}
prompt_shell_depth () {
# SHLVL
depth="$SHLVL"
prompt_segment $color_prompt_git_orange $color_prompt_git_orange " [$depth]"
}
prompt_nix_shell () {
if [[ -n $IN_NIX_SHELL ]]; then
color=cyan
prompt_segment $color_prompt_dir_bg $color_prompt_git_blue
print -Pn " <nix-$IN_NIX_SHELL>"
fi
}
prompt_virtualenv () {
if [[ -n $VIRTUAL_ENV_PROMPT ]]; then
color=cyan
prompt_segment $color_prompt_dir_bg $color_prompt_git_orange
print -Pn " $(basename $VIRTUAL_ENV_PROMPT)"
fi
}
prompt_end () {
[[ $CURRENT_BG == 8 ]] && print -n "%{%F{white}%} ❯" || print -n "%{%F{white}%} ❯"
}
# status:
# - error
# - jobs
# - vagrant
# - nodejs
prompt_status () {
[[ $RETVAL -ne 0 ]] && SYMBOLS+="%{%F{red}%}$RETVAL "
[[ $(jobs -l | wc -l) -gt 0 ]] && SYMBOLS+="%{%F{cyan}%}J "
if [[ -d ./.vagrant/machines ]]; then
if [[ -f .vagrant/machines/default/virtualbox/id && $(VBoxManage list runningvms | grep -c $(/bin/cat .vagrant/machines/*/*/id)) -gt 0 ]]; then
SYMBOLS+="%{%F{green}%}V "
else
SYMBOLS+="%{%F{red}%}V "
fi
fi
if [[ -d ./node_modules ]]; then
SYMBOLS+="%{%F{green}%}`node -v 2> /dev/null` "
fi
prompt_segment $FG default "$SYMBOLS"
}
prompt () {
CURRENT_BG="NONE"
prompt_context
prompt_vpn
prompt_shell_depth
prompt_nix_shell
prompt_virtualenv
prompt_dir
prompt_git
prompt_end
}
prompt_precmd () {
RETVAL=$?
vcs_info
PROMPT='%{%f%b%k%}$(prompt) '
RPROMPT='%{%f%b%k%}$(prompt_status) '
}
prompt_setup () {
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
prompt_opts=(cr subst percent)
add-zsh-hook precmd prompt_precmd
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' check-for-changes false
zstyle ':vcs_info:git*' formats '%b'
zstyle ':vcs_info:git*' actionformats '%b (%a)'
}
prompt_setup "$@"