forked from Remz-Jay/vim-config
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtuurlijk.zsh-theme
215 lines (188 loc) · 6.15 KB
/
tuurlijk.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
#!/usr/bin/env zsh
# vim:ft=zsh
# @see prompt_tuurlijk_help
local -A symbols
local -A colours
local newSymbol
local newColour
symbols=(
'branch' ''
'hash' '➦'
)
# Use extended color palette if available
if [[ -n ${terminfo[colors]} && ${terminfo[colors]} -ge 256 ]]; then
colours=(
'pwd' 250
'pwdBg' 238
'userHost' 16
'userHostBg' 254
'exit' 124
'exitBg' 245
'root' 245
'rootBg' 52
'exec' 208
'vcs' 244
'vcsBg' 236
'vcsClean' 28
'vcsDirty' 124
)
else
colours=(
'pwd' white
'pwdBg' blue
'userHost' black
'userHostBg' cyan
'exit' red
'exitBg' cyan
'root' red
'rootBg' yellow
'exec' yellow
'vcs' white
'vcsBg' blue
'vcsClean' green
'vcsDirty' red
)
fi
# Set symbols from user preferences (zstyle ':theme:tuurlijk:branch' symbol '')
for symbol in ${(@k)symbols}; do
zstyle -s ":theme:tuurlijk:$symbol" symbol newSymbol && symbols[$symbol]=$newSymbol
done
# Set colours from user preferences (zstyle ':theme:tuurlijk:pwd' colour 250)
for colour in ${(@k)colours}; do
zstyle -s ":theme:tuurlijk:$colour" colour newColour && colours[$colour]=$newColour
done
# Define prompts
prompt_tuurlijk_setup() {
if ! type shrink_path > /dev/null; then
echo -e " \033[1;31m✖\033[0m Please install the 'shrink-path' plugin:"
echo " https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/shrink-path"
echo " This prompt uses it to generate a short readable path."
fi
# Load required modules
autoload -Uz vcs_info
# vcs_info format strings, formatted using zformat
# See: man zshmodules
#
# max-exports: Defines the maximum number of vcs_info_msg_*_ variables vcs_info will set.
# %b: branch
# %a: action (rebase/merge)
# %i: revision number or identifier
# %s: version control system
# %r: name of the root directory of the repository
# %S: path relative to the repository root directory
# %m: in case of Git, show information about stashes
# %u: unstaged changes in the repository
# %c: staged changes in the repository
#
zstyle ':vcs_info:*' enable git hg
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' max-exports 5
zstyle ':vcs_info:*:*' unstagedstr '!'
zstyle ':vcs_info:*:*' stagedstr '+'
zstyle ':vcs_info:*:*' formats \
"%F{$colours[vcsBg]}%K{$colours[vcsBg]}%F{$colours[vcs]} %F{$colours[vcsClean]}${symbols[branch]} %F{$colours[vcs]}%1.25b" \
"%F{$colours[vcsBg]}%K{$colours[vcsBg]}%F{$colours[vcs]} %F{$colours[vcsDirty]}${symbols[branch]} %F{$colours[vcs]}%1.25b" \
"$symbols[hash] %7.7i" \
"%r" \
"%u%c"
zstyle ':vcs_info:*:* actionformats' \
"%F{$colours[vcsBg]}%K{$colours[vcsBg]}%F{$colours[vcs]} %F{$colours[vcsClean]}${symbols[branch]} %F{$colours[vcs]}%1.25b" \
"%F{$colours[vcsBg]}%K{$colours[vcsBg]}%F{$colours[vcs]} %F{$colours[vcsDirty]}${symbols[branch]} %F{$colours[vcs]}%1.25b" \
"$symbols[hash] %7.7i" \
"%r" \
"%u%c (%a)"
autoload -Uz colors && colors
autoload -Uz add-zsh-hook
prompt_opts=(percent subst)
add-zsh-hook preexec _prompt_tuurlijk_preexec
add-zsh-hook precmd _prompt_tuurlijk_precmd
# Prompt format strings
#
# %F: foreground color dict
# %f: reset foreground color
# %K: background color dict
# %k: reset background color
# %~: current path
# %*: time
# %n: username
# %m: shortname host
# %(?..): prompt conditional - %(condition.true.false)
PROMPT_PWD=' $(shrink_path -f) '
PROMPT_EXIT="%K{$colours[exitBg]}%F{$colours[exit]}%(?.. ✘ %K{$colours[pwdBg]}%F{$colours[exitBg]})%K{$colours[pwdBg]}%F{$colours[pwd]}"
PROMPT_SU="%(!.%k%F{$colours[pwdBg]}%K{$colours[rootBg]} ⚡ %F{$colours[rootBg]}%k.%k%F{$colours[pwdBg]})%{%f%k%b%} "
PROMPT='${PROMPT_EXIT}${(e)${PROMPT_PWD}}${PROMPT_SU}'
RPROMPT_HOST="%F{$colours[userHostBg]}${SSH_TTY:+}%K{$colours[userHostBg]}%F{$colours[userHost]}${SSH_TTY:+ %n@%m }%{%f%k%b%}"
RPROMPT_EXEC_COLOUR="%F{$colours[exec]}"
RPROMPT='$(_prompt_tuurlijk_vcs_path_and_branch)${RPROMPT_EXEC_COLOUR}$(_prompt_tuurlijk_cmd_exec_time)${RPROMPT_HOST}'
}
# Fastest possible way to check if repo is dirty
_prompt_tuurlijk_vcs_is_git_dirty() {
if [[ $(command git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
return true
else
return false
fi
}
# Display information about the current path and branch
_prompt_tuurlijk_vcs_path_and_branch() {
local segment
if [[ -n "$vcs_info_msg_2_" ]]; then
if [[ -z $vcs_info_msg_4_ ]]; then
segment+=( "$vcs_info_msg_0_" )
else
segment+=( "$vcs_info_msg_1_" )
segment+=( "$vcs_info_msg_4_" )
fi
segment+=( "$vcs_info_msg_2_" )
[[ -n "$vcs_info_msg_3_" ]] && segment+=( "| $vcs_info_msg_3_ " )
fi
echo $segment
}
# Display information about the current repository
_prompt_tuurlijk_vcs_repository() {
echo "${vcs_info_msg_0_}"
}
# Displays the exec time of the last command if set threshold was exceeded
_prompt_tuurlijk_cmd_exec_time() {
local stop=`date +%s`
local start=${_cmd_timestamp:-$stop}
let local elapsed=$stop-$start
[ $elapsed -gt 5 ] && echo "${elapsed}s "
}
# Get the initial timestamp for cmd_exec_time
_prompt_tuurlijk_preexec() {
_cmd_timestamp=`date +%s`
}
# Get version control info before we start outputting stuff
_prompt_tuurlijk_precmd() {
vcs_info
}
prompt_tuurlijk_help () {
cat <<EOH
Tuurlijk's lightweight prompt
You will need a Powerline capable font:
https://github.com/powerline/powerline
And the 'shrink-path' plugin:
https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/shrink-path
You can style this prompt using zstyles in your .zshrc:
# Set custom prompt colours
zstyle ':theme:tuurlijk:pwd' colour 250
zstyle ':theme:tuurlijk:pwdBg' colour 238
zstyle ':theme:tuurlijk:exit' colour 124
zstyle ':theme:tuurlijk:exitBg' colour 245
zstyle ':theme:tuurlijk:root' colour 234
zstyle ':theme:tuurlijk:rootBg' colour 52
zstyle ':theme:tuurlijk:userHost' colour 16
zstyle ':theme:tuurlijk:userHostBg' colour 245
zstyle ':theme:tuurlijk:exec' colour 220
zstyle ':theme:tuurlijk:vcs' colour 250
zstyle ':theme:tuurlijk:vcsBg' colour 238
zstyle ':theme:tuurlijk:vcsClean' colour 28
zstyle ':theme:tuurlijk:vcsDirty' colour 124
# Set custom prompt symbols
zstyle ':theme:tuurlijk:branch' symbol
zstyle ':theme:tuurlijk:hash' symbol ➦
EOH
}
prompt_tuurlijk_setup "$@"