-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsenpai.zsh-theme
209 lines (179 loc) · 5.12 KB
/
senpai.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
# Senpai
# by Sergi Barroso
# https://github.com/hiroru/senpai-zsh
# MIT License
k8s_info() {
if [ ! -z ${KUBECONFIG} ]; then
k8s_context=$(awk '/current-context/{print $2}' $KUBECONFIG)
elif [ -f "$HOME/.kube/config" ]; then
k8s_context=$(awk '/current-context/{print $2}' $HOME/.kube/config)
fi
if [ ! -z ${k8s_context} ]; then
echo " ${cyan}⎈ ${k8s_context}%f"
fi
}
aws_info() {
if [ ! -z ${AWS_PROFILE} ]; then
echo " ${yellow}ⓦ ${AWS_PROFILE}%f"
elif [ ! -z ${AWS_DEFAULT_PROFILE} ]; then
echo " ${yellow}ⓦ ${AWS_DEFAULT_PROFILE}%f"
fi
}
azure_info() {
if [ -f "$HOME/.azure/config" ]; then
azure_cloud=$(awk '/name/{print tolower($3)}' $HOME/.azure/config)
if [ ! -z ${azure_cloud} ]; then
echo " ${blue}ⓐ ${azure_cloud}%f"
fi
fi
}
gcp_info() {
if [ -f "$HOME/.config/gcloud/active_config" ]; then
gcp_profile=$(cat $HOME/.config/gcloud/active_config)
gcp_project=$(awk '/project/{print $3}' $HOME/.config/gcloud/configurations/config_$gcp_profile)
if [ ! -z ${gcp_project} ]; then
echo " ${darkgreen}ⓖ ${gcp_project}%f"
fi
fi
}
define_var() {
local varname="$1"
typeset -p "$varname" > /dev/null 2>&1
}
set_default() {
local varname="$1"
local default_value="$2"
define_var "$varname" || typeset -g "$varname"="$default_value"
}
prompt_senpai_git() {
[[ -n ${git_info} ]] && print -n " ${(e)git_info[prompt]}"
}
prompt_senpai_virtualenv() {
[[ -n ${VIRTUAL_ENV} ]] && print -n " (%F{blue}${VIRTUAL_ENV:t}%f)"
}
prompt_senpai_precmd() {
(( ${+functions[git-info]} )) && git-info
}
prompt_senpai_time() {
print -n "[${white}%*] "
}
prompt_senpai_setup() {
# Set default values
[[ -n ${VIRTUAL_ENV} ]] && export VIRTUAL_ENV_DISABLE_PROMPT=1
set_default SENPAI_THEME_DARK true
set_default SENPAI_SHOW_TIME true
set_default SENPAI_SHOW_USER true
set_default SENPAI_SHOW_PATH true
set_default SENPAI_SHOW_GIT true
set_default SENPAI_SHOW_K8S true
set_default SENPAI_SHOW_AWS true
set_default SENPAI_SHOW_GCP true
set_default SENPAI_SHOW_AZURE true
typeset -g blue
typeset -g brown
typeset -g cyan
typeset -g green
typeset -g magenta
typeset -g red
typeset -g white
typeset -g yellow
# Choose dark or bright color schema and use extended color palette if available
if [[ $SENPAI_THEME_DARK == true ]]; then
if [[ -n ${terminfo[colors]} && ${terminfo[colors]} -ge 256 ]]; then
blue='%F{33}'
brown='%F{166}'
cyan='%F{74}'
green='%F{64}'
darkgreen='%F{34}'
red='%F{9}'
darkred='%F{160}'
white='%F{15}'
yellow='%F{214}'
else
blue='%F{blue}'
brown='%F{brown}'
cyan='%F{cyan}'
green='%F{green}'
red='%F{red}'
white='%F{white}'
yellow='%F{yellow}'
fi
else
if [[ -n ${terminfo[colors]} && ${terminfo[colors]} -ge 256 ]]; then
blue='%F{21}'
brown='%F{208}'
cyan='%F{33}'
green='%F{76}'
darkgreen='%F{70}'
red='%F{9}'
darkred='%F{160}'
white='%F{0}'
yellow='%F{214}'
else
blue='%F{blue}'
brown='%F{brown}'
cyan='%F{cyan}'
green='%F{green}'
red='%F{red}'
white='%F{black}'
yellow='%F{yellow}'
fi
fi
autoload -Uz add-zsh-hook
autoload -Uz colors && colors
prompt_opts=(cr percent sp subst)
add-zsh-hook precmd prompt_senpai_precmd
zstyle ':zim:git-info' verbose 'yes'
zstyle ':zim:git-info:branch' format '%b'
zstyle ':zim:git-info:commit' format '%c'
zstyle ':zim:git-info:action' format "(${limegreen}%s%f)"
zstyle ':zim:git-info:unindexed' format "${brown}●"
zstyle ':zim:git-info:indexed' format "${green}●"
zstyle ':zim:git-info:untracked' format "${red}●"
zstyle ':zim:git-info:keys' format 'prompt' "${white}(%b%c%I%i%u${white})%f%s"
# Init PROMPT
PROMPT=""
# Build prompt based on user settings
# Do not print timestamp if it is disabled
if [[ $SENPAI_SHOW_TIME == true ]]; then
PROMPT+="\$(prompt_senpai_time)"
fi
# Do not print user if it is disabled
if [[ $SENPAI_SHOW_USER == true ]]; then
PROMPT+="${brown}%n%f"
fi
# Do not print path if it is disabled
if [[ $SENPAI_SHOW_USER == true ]] && [[ $SENPAI_SHOW_PATH == true ]]; then
PROMPT+=" in ${blue}%~%f"
elif [[ $SENPAI_SHOW_PATH == true ]]; then
PROMPT+="${blue}%~%f"
fi
# Do not print git status if it is disabled
if [[ $SENPAI_SHOW_GIT == true ]]; then
PROMPT+="\$(prompt_senpai_git)"
fi
# Do not print virtual env if it is disabled
if [[ $SENPAI_SHOW_VIRT == true ]]; then
PROMPT+="\$(prompt_senpai_virtualenv)"
fi
# Do not print virtual env if it is disabled
if [[ $SENPAI_SHOW_K8S == true ]]; then
PROMPT+="\$(k8s_info)"
fi
# Do not print virtual env if it is disabled
if [[ $SENPAI_SHOW_AWS == true ]]; then
PROMPT+="\$(aws_info)"
fi
# Do not print virtual env if it is disabled
if [[ $SENPAI_SHOW_GCP == true ]]; then
PROMPT+="\$(gcp_info)"
fi
# Do not print virtual env if it is disabled
if [[ $SENPAI_SHOW_AZURE == true ]]; then
PROMPT+="\$(azure_info)"
fi
# Add the final prompt
PROMPT+=" %(?.${white}.${darkred})❯%f "
RPROMPT=''
}
prompt_senpai_setup "$@"