-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtq.zsh-theme
233 lines (202 loc) · 6.32 KB
/
tq.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
#
# tq ZSH Theme
#
# Author: Tian Qi
# License: MIT
# https://github.com/kitian616/tq-zsh-theme
# Characters
TQ_BRANCH_SYMBOL="${TQ_BRANCH_SYMBOL:="\ue0a0"}"
TQ_SSH_SYMBOL="${TQ_SSH_SYMBOL:="\ue0a2"}"
TQ_FOOD_SYMBOL="${TQ_FOOD_SYMBOL:="🍚"}"
TQ_NIGHT_SYMBOL="${TQ_NIGHT_SYMBOL:="🌙"}"
# Privileges
TQ_PRIVILEGES_PREFIX="${TQ_PRIVILEGES_PREFIX:=""}"
TQ_PRIVILEGES_SUFFIX="${TQ_PRIVILEGES_SUFFIX:=""}"
TQ_PRIVILEGES_SYMBOL="${TQ_PRIVILEGES_SYMBOL:="=>"}"
TQ_PRIVILEGES_COLOR="${TQ_PRIVILEGES_COLOR:="green"}"
TQ_PRIVILEGES_STYLE="${TQ_PRIVILEGES_STYLE:="bold"}"
# User
TQ_USER_PREFIX="${TQ_USER_PREFIX:=""}"
TQ_USER_SUFFIX="${TQ_USER_SUFFIX:=""}"
TQ_USER_COLOR="${TQ_USER_COLOR:="yellow"}"
TQ_SUPERUSER_COLOR="${TQ_SUPERUSER_COLOR:="red"}"
# Env
TQ_ENV_PREFIX="${TQ_ENV_PREFIX:=""}"
TQ_ENV_SUFFIX="${TQ_ENV_SUFFIX:=""}"
TQ_ENV_COLOR="${TQ_ENV_COLOR:="yellow"}"
# Tip
TQ_TIP_PREFIX="${TQ_TIP_PREFIX:=""}"
TQ_TIP_SUFFIX="${TQ_TIP_SUFFIX:=""}"
TQ_TIP_COLOR="${TQ_TIP_COLOR:="yellow"}"
# Dictionary
TQ_DICTIONARY_PREFIX="${TQ_DICTIONARY_PREFIX:=""}"
TQ_DICTIONARY_SUFFIX="${TQ_DICTIONARY_SUFFIX:=""}"
TQ_DICTIONARY_COLOR="${TQ_DICTIONARY_COLOR:="cyan"}"
# Git brance
TQ_GIT_BRANCE_PREFIX="${TQ_BRANCH_SYMBOL} "
TQ_GIT_BRANCE_SUFFIX="${TQ_GIT_BRANCE_SUFFIX:=""}"
TQ_GIT_BRANCE_COLOR="${TQ_GIT_BRANCE_COLOR:="magenta"}"
# Git status
TQ_GIT_STATUS_UNTRACKED="${TQ_GIT_STATUS_UNTRACKED:="?"}"
TQ_GIT_STATUS_ADDED="${TQ_GIT_STATUS_ADDED:="+"}"
TQ_GIT_STATUS_MODIFIED="${TQ_GIT_STATUS_MODIFIED:="!"}"
TQ_GIT_STATUS_RENAMED="${TQ_GIT_STATUS_RENAMED:="»"}"
TQ_GIT_STATUS_DELETED="${TQ_GIT_STATUS_DELETED:="✘"}"
TQ_GIT_STATUS_STASHED="${TQ_GIT_STATUS_STASHED:="$"}"
TQ_GIT_STATUS_UNMERGED="${TQ_GIT_STATUS_UNMERGED:="="}"
TQ_GIT_STATUS_AHEAD="${TQ_GIT_STATUS_AHEAD:="⇡"}"
TQ_GIT_STATUS_BEHIND="${TQ_GIT_STATUS_BEHIND:="⇣"}"
TQ_GIT_STATUS_PREFIX="${TQ_GIT_STATUS_PREFIX:="["}"
TQ_GIT_STATUS_SUFFIX="${TQ_GIT_STATUS_SUFFIX:="]"}"
TQ_GIT_STATUS_COLOR="${TQ_GIT_STATUS_COLOR:="red"}"
# Time
TQ_TIME_PREFIX="${TQ_TIME_PREFIX:="["}"
TQ_TIME_SUFFIX="${TQ_TIME_SUFFIX:="]"}"
TQ_TIME_COLOR="${TQ_TIME_COLOR:=""}"
# Exit code
TQ_EXIT_CODE_PREFIX="${TQ_EXIT_CODE_PREFIX:=""}"
TQ_EXIT_CODE_SUFFIX="${TQ_EXIT_CODE_SUFFIX:=""}"
TQ_EXIT_CODE_COLOR="${TQ_EXIT_CODE_COLOR:="red"}"
# ZSH theme git prompt setting
ZSH_THEME_GIT_PROMPT_UNTRACKED=$TQ_GIT_STATUS_UNTRACKED
ZSH_THEME_GIT_PROMPT_ADDED=$TQ_GIT_STATUS_ADDED
ZSH_THEME_GIT_PROMPT_MODIFIED=$TQ_GIT_STATUS_MODIFIED
ZSH_THEME_GIT_PROMPT_RENAMED=$TQ_GIT_STATUS_RENAMED
ZSH_THEME_GIT_PROMPT_DELETED=$TQ_GIT_STATUS_DELETED
ZSH_THEME_GIT_PROMPT_STASHED=$TQ_GIT_STATUS_STASHED
ZSH_THEME_GIT_PROMPT_UNMERGED=$TQ_GIT_STATUS_UNMERGED
ZSH_THEME_GIT_PROMPT_AHEAD=$TQ_GIT_STATUS_AHEAD
ZSH_THEME_GIT_PROMPT_BEHIND=$TQ_GIT_STATUS_BEHIND
ZSH_THEME_GIT_PROMPT_DIVERGED=$TQ_GIT_STATUS_DIVERGED
_get_pwd() {
local git_root=$PWD
while [[ $git_root != / && ! -e $git_root/.git ]]; do
git_root=$git_root:h
done
if [[ $git_root == / ]]; then
unset git_root
prompt_short_dir=%~
else
parent=${git_root%\/*}
prompt_short_dir=${PWD#$parent/}
fi
echo "$prompt_short_dir"
}
_get_date_string() {
echo "$(date +%H:%M:%S)"
}
_get_hour() {
echo "$(date +%H)"
}
# 0: is git
_is_git() {
command git rev-parse --is-inside-work-tree &>/dev/null
echo "$?"
}
# 0: is superuser
_is_superuser() {
echo "$UID"
}
_get_prompt_section() {
if [[ $# -eq 1 ]]; then
echo "$1"
elif [[ $# -eq 2 ]]; then
echo "%{$fg[$2]%}$1%{$reset_color%}"
elif [[ $# -eq 3 ]]; then
echo "%{$fg[$2]$terminfo[$3]%}$1%{$reset_color%}"
elif [[ $# -eq 4 ]]; then
echo "%{$fg[$2]%}$terminfo[$3]$bg[$4]$1%{$reset_color%}"
fi
}
# User
local prompt_user='$(_get_prompt_user)'
_get_prompt_user() {
local superuser_or_not=$(_is_superuser)
[[ $LOGNAME != $USER ]] || [[ $superuser_or_not -eq 0 ]] || [[ -n $SSH_CONNECTION ]] || return
local prompt_text
if [[ -n $SSH_CONNECTION ]]; then
prompt_text=${TQ_USER_PREFIX}${USER}@$(hostname -s)${TQ_USER_SUFFIX}
else
prompt_text=${TQ_USER_PREFIX}${USER}${TQ_USER_SUFFIX}
fi
if [[ $superuser_or_not -eq 0 ]]; then
echo "$(_get_prompt_section\
$prompt_text\
$TQ_SUPERUSER_COLOR\
bold): "
else
echo "$(_get_prompt_section\
$prompt_text\
$TQ_USER_COLOR): "
fi
}
# env
local prompt_evn='$(_get_prompt_env)'
_get_prompt_env() {
if [[ -n $SSH_CONNECTION ]]; then
echo "$(_get_prompt_section\
${TQ_ENV_PREFIX}${TQ_SSH_SYMBOL}${TQ_ENV_SUFFIX}\
${TQ_ENV_COLOR}) "
fi
}
# Privileges
local prompt_privileges="\
$(_get_prompt_section\
${TQ_PRIVILEGES_PREFIX}${TQ_PRIVILEGES_SYMBOL}${TQ_PRIVILEGES_SUFFIX}\
${TQ_PRIVILEGES_COLOR}\
${TQ_PRIVILEGES_STYLE})"
# Directory
local prompt_directory="\
$(_get_prompt_section\
${TQ_DICTIONARY_PREFIX}'$(_get_pwd)'${TQ_DICTIONARY_SUFFIX}\
${TQ_DICTIONARY_COLOR}) "
# Git brance
local prompt_git_brance='$(_get_prompt_git_brance)'
_get_prompt_git_brance() {
[[ $(_is_git) -eq 0 ]] || return
echo "$(_get_prompt_section\
${TQ_GIT_BRANCE_PREFIX}$(git_current_branch)${TQ_GIT_BRANCE_SUFFIX}\
${TQ_GIT_BRANCE_COLOR}) "
}
# Git satatus
local prompt_git_status='$(_get_prompt_git_status)'
_get_prompt_git_status() {
local git_status=$(git_prompt_status)
[[ $(_is_git) -eq 0 ]] && [[ -n $git_status ]] || return
echo "$(_get_prompt_section\
${TQ_GIT_STATUS_PREFIX}${git_status}${TQ_GIT_STATUS_SUFFIX}\
${TQ_GIT_STATUS_COLOR}) "
}
# Exit code
local prompt_exit_code="\
%(?,,$(_get_prompt_section\
${TQ_EXIT_CODE_PREFIX}%?${TQ_EXIT_CODE_SUFFIX}\
${TQ_EXIT_CODE_COLOR}))"
# Time
local prompt_time="\
$(_get_prompt_section\
${TQ_TIME_PREFIX}'$(_get_date_string)'${TQ_TIME_SUFFIX}\
${TQ_TIME_COLOR}
)"
# Tip
local prompt_tip='$(_get_prompt_tip)'
_get_prompt_tip() {
local hour=$(_get_hour)
if [[ $hour -ge 12 ]] && [[ $hour -le 13 ]]; then
echo "$(_get_prompt_section ${TQ_FOOD_SYMBOL} ${TQ_TIP_COLOR}) "
elif [[ $hour -ge 21 ]] || [[ $hour -le 3 ]]; then
echo "$(_get_prompt_section ${TQ_NIGHT_SYMBOL} ${TQ_TIP_COLOR}) "
fi
}
PROMPT="
$prompt_evn\
$prompt_user\
$prompt_directory\
$prompt_git_brance\
$prompt_git_status
$prompt_exit_code\
$prompt_privileges"
RPROMPT="\
$prompt_tip\
$prompt_time\
"