-
Notifications
You must be signed in to change notification settings - Fork 1
/
vero.zsh-theme
160 lines (135 loc) · 4.92 KB
/
vero.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
# Vero theme for Zsh
#
# Copyright (c) 2017-2021 Jade Michael Thornton
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# The software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the software or the use or other dealings in the
# software.
autoload colors && colors
ZSH_THEME_NVM_PROMPT_PREFIX="⟦nvm "
ZSH_THEME_NVM_PROMPT_SUFFIX="⟧"
ZSH_THEME_PYENV_PROMPT_PREFIX="⟦py "
ZSH_THEME_PYENV_PROMPT_SUFFIX="⟧"
ZSH_THEME_GIT_PROMPT_PREFIX="⟦%{$fg_bold[cyan]%}%{$reset_color%}%{$fg_bold[white]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}⟧"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[green]%}✓%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[cyan]%}▴%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[magenta]%}▾%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}•%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}•%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}•%{$reset_color%}"
vero_git_branch () {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
vero_git_status() {
_STATUS=""
# check status of files
_INDEX=$(command git status --porcelain 2> /dev/null)
if [[ -n "$_INDEX" ]]; then
if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
if $(echo "$_INDEX" | command grep -q '^UU '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
else
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
# check status of local repository
_INDEX=$(command git status --porcelain -b 2> /dev/null)
if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
if $(echo "$_INDEX" | command grep -q '^## .*behind'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
if $(command git rev-parse --verify refs/stash &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
fi
echo $_STATUS
}
vero_git_prompt () {
local _branch=$(vero_git_branch)
local _status=$(vero_git_status)
local _result=""
if [[ "${_branch}x" != "x" ]]; then
_result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch"
if [[ "${_status}x" != "x" ]]; then
_result="$_result $_status"
fi
_result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
echo $_result
}
function ssh_connection() {
if [[ -n $SSH_CONNECTION ]]; then
echo "%{$fg_bold[red]%} (ssh)"
fi
}
function nvm_prompt_info() {
which nvm &>/dev/null || return
local nvm_prompt=${$(nvm current)#v}
echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
}
function pyenv_prompt_info() {
which pyenv &>/dev/null || return
local pyenv_prompt="${$(pyenv version)% \(*\)}"
echo "${ZSH_THEME_PYENV_PROMPT_PREFIX}${pyenv_prompt}${ZSH_THEME_PYENV_PROMPT_SUFFIX}"
}
_PATH="%{$fg_bold[white]%}%~%{$reset_color%} "
if [[ $EUID -eq 0 ]]; then
_USERNAME="%{$fg_bold[red]%}%n"
_LIBERTY="%{$fg[red]%}#"
else
_USERNAME="%{$fg_bold[white]%}%n"
_LIBERTY="%{$fg[green]%}$"
fi
_USERNAME="$_USERNAME%{$reset_color%}@%m"
_LIBERTY="$_LIBERTY%{$reset_color%}"
get_space () {
local STR=$1$2
local zero='%([BSUbfksu]|([FB]|){*})'
local LENGTH=${#${(S%%)STR//$~zero/}}
local SPACES=""
(( LENGTH = ${COLUMNS} - $LENGTH - 1))
for i in {0..$LENGTH}
do
SPACES="$SPACES "
done
echo $SPACES
}
vero_precmd () {
_TIME="%*"
_ENV_LINE="$(pyenv_prompt_info) $(nvm_prompt_info) $(vero_git_prompt)"
_SSH="$(ssh_connection) "
_PROMPT="$_TIME$_SSH$_USERNAME:$_PATH$_ENV_LINE"
print
print -rP "$_PROMPT"
}
setopt prompt_subst
PROMPT='λ $_LIBERTY '
autoload -U add-zsh-hook
add-zsh-hook precmd vero_precmd