-
Notifications
You must be signed in to change notification settings - Fork 0
/
kexplo.zsh-theme
115 lines (95 loc) · 2.77 KB
/
kexplo.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
# ZSH Theme emulating the Fish shell's default prompt.
# customized by kexplo
_fishy_collapsed_wd() {
echo $(pwd | perl -pe '
BEGIN {
binmode STDIN, ":encoding(UTF-8)";
binmode STDOUT, ":encoding(UTF-8)";
}; s|^$ENV{HOME}|~|g; s|/([^/.])[^/]*(?=/)|/$1|g; s|/\.([^/])[^/]*(?=/)|/.$1|g
')
}
PROMPT2="%{$fg[red]%}\ %{$reset_color%}"
EXEC_TIMER_PROMPT=""
# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html
prompt_venv() {
echo -n "$(virtualenv_prompt_info)"
}
prompt_user() {
local user_color='green'; [ $UID -eq 0 ] && user_color='red'
echo -n "%n@%m:%{$fg[$user_color]%}"
}
prompt_path() {
echo -n "$(_fishy_collapsed_wd)%{$reset_color%}"
}
prompt_git() {
echo -n "%{$fg[yellow]%}$(git_prompt_info)%{$reset_color%}%(!.#.$)"
}
prompt_time() {
echo -n " %{$fg_bold[gray]%}[%*]%{$reset_color%}"
}
prompt_kube() {
[[ "${KUBE_PS1_ENABLED}" == "off" ]] && return
echo -n " %{$fg_bold[blue]%}[${KUBE_PS1_CONTEXT}/${KUBE_PS1_NAMESPACE}]%{$reset_color%}"
}
prompt_return_status() {
echo -n " %{$fg_bold[red]%}%(?..%?)%{$reset_color%} ${EXEC_TIMER_PROMPT}"
}
prompt_shell() {
echo -n '\n%(!.#.$)'
}
build_prompt() {
prompt_venv
prompt_user
prompt_path
prompt_git
prompt_time
prompt_kube
prompt_return_status
prompt_shell
}
PROMPT='$(build_prompt) '
ZSH_THEME_GIT_PROMPT_PREFIX=":"
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_DIRTY=""
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg_bold[green]%}+"
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg_bold[blue]%}!"
ZSH_THEME_GIT_PROMPT_DELETED="%{$fg_bold[red]%}-"
ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg_bold[magenta]%}>"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[yellow]%}#"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[cyan]%}?"
ZSH_THEME_VIRTUALENV_PREFIX="%{$bg[blue]%}%{$fg_bold[white]%}("
ZSH_THEME_VIRTUALENV_SUFFIX=")%{$reset_color%}"
# show elapsed time at the RPROMPT if slower than 3sec.
start-timer() {
COMMAND_TIMER="$SECONDS"
}
stop-timer-rprompt() {
local return_status="%{$fg_bold[red]%}%(?..%?)%{$reset_color%}"
#RPROMPT='${return_status}$(git_prompt_info)$(git_prompt_status)%{$reset_color%}'
# RPROMPT="${return_status}%{$reset_color%} "
if [[ -z "$COMMAND_TIMER" ]]
then
return
fi
local elapsed
elapsed="$(($SECONDS - $COMMAND_TIMER))"
unset COMMAND_TIMER
if [[ "$elapsed" -lt 3 ]]
then
# ~3sec: show nothing
EXEC_TIMER_PROMPT=""
return
elif [[ "$elapsed" -lt 600 ]]
then
# 3sec~10min: ↳42sec (yellow)
# RPROMPT+="%F{yellow}↳%S${elapsed}sec%s%f"
EXEC_TIMER_PROMPT="%F{yellow}↳%S${elapsed}sec%s%f"
else
# 10min~: ↳23min (red)
# RPROMPT+="%F{red}↳%S$((elapsed/60))min%s%f"
EXEC_TIMER_PROMPT="%F{yellow}↳%S${elapsed}sec%s%f"
fi
}
add-zsh-hook preexec start-timer
add-zsh-hook precmd stop-timer-rprompt