-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzsh1999-docker.zsh-theme
190 lines (165 loc) Β· 5.09 KB
/
zsh1999-docker.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
CURRENT_BG='NONE'
SEGMENT_SEPARATOR_RIGHT='\ue0b2'
SEGMENT_SEPARATOR_LEFT='\ue0b0'
ZSH_THEME_GIT_PROMPT_UNTRACKED=" β"
ZSH_THEME_GIT_PROMPT_DIRTY=''
ZSH_THEME_GIT_PROMPT_STASHED=' β'
ZSH_THEME_GIT_PROMPT_DIVERGED=' β‘'
ZSH_THEME_GIT_PROMPT_ADDED=" β"
ZSH_THEME_GIT_PROMPT_MODIFIED=" βΉ"
ZSH_THEME_GIT_PROMPT_DELETED=" β"
ZSH_THEME_GIT_PROMPT_RENAMED=" β"
ZSH_THEME_GIT_PROMPT_UNMERGED=" β"
ZSH_THEME_GIT_PROMPT_AHEAD=' β¬'
ZSH_THEME_GIT_PROMPT_BEHIND=' β¬'
ZSH_THEME_GIT_PROMPT_DIRTY=' Β±'
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_LEFT%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
prompt_segment_right() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
echo -n "%K{$CURRENT_BG}%F{$1}$SEGMENT_SEPARATOR_RIGHT%{$bg%}%{$fg%} "
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_LEFT"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
prompt_user_hostname() {
local user=$(whoami)
prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m"
}
prompt_git() {
local ref dirty
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2>/dev/null)
if [[ -n $dirty ]]; then
prompt_segment magenta black
else
prompt_segment green black
fi
echo -n "\ue0a0 ${ref/refs\/heads\//}$dirty"$(git_prompt_status)
fi
}
prompt_dir() {
prompt_segment blue white '%2~'
}
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{yellow}%}β"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}β‘"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}β"
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
prompt_time() {
prompt_segment_right white black '%D{%H:%M:%S[%f/%m]} '
}
prompt_connection() {
local connection_status=""
if [[ "$(nmcli networking connectivity)" == "full" ]]; then
connection_status="\u21D5"
else
connection_status="\u00D7"
fi
prompt_segment_right green black "$connection_status "
}
prompt_battery() {
local battery_status=''
if [[ "$(cat /sys/class/power_supply/ADP0/online)" == "0" ]]; then
battery_status="\u00D7"
else
battery_status="\u21AF"
fi
prompt_segment_right yellow black "$(cat /sys/class/power_supply/BAT0/capacity)%% $battery_status "
}
prompt_docker_containers(){
prompt_segment_right blue white "\u25A5 $(docker container ls -q | wc -l)/$(docker container ls -aq | wc -l) "
}
build_prompt() {
RETVAL=$?
prompt_status
prompt_user_hostname
prompt_dir
prompt_git
prompt_end
}
ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local cb=$(current_branch)
if [ -n "$cb" ]; then
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}
# Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time.
function git_time_since_commit() {
if git rev-parse --git-dir >/dev/null 2>&1; then
# Only proceed if there is actually a commit.
if [[ $(git log 2>&1 >/dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# Get the last commit.
last_commit=$(git log --pretty=format:'%at' -1 2>/dev/null)
now=$(date +%s)
seconds_since_last_commit=$((now - last_commit))
# Totals
MINUTES=$((seconds_since_last_commit / 60))
HOURS=$((seconds_since_last_commit / 3600))
# Sub-hours and sub-minutes
DAYS=$((seconds_since_last_commit / 86400))
SUB_HOURS=$((HOURS % 24))
SUB_MINUTES=$((MINUTES % 60))
if [[ -n $(git status -s 2>/dev/null) ]]; then
if [ "$MINUTES" -gt 30 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
elif [ "$MINUTES" -gt 10 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
fi
if [ "$HOURS" -gt 24 ]; then
echo "($COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%})"
elif [ "$MINUTES" -gt 60 ]; then
echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%})"
else
echo "($COLOR${MINUTES}m%{$reset_color%})"
fi
fi
fi
}
build_rprompt() {
prompt_docker_containers
prompt_connection
prompt_battery
prompt_time
}
PROMPT='%{%f%b%k%}$(build_prompt) '
RPROMPT='%{%f%b%k%}$(git_time_since_commit)$(build_rprompt)'