-
Notifications
You must be signed in to change notification settings - Fork 7
/
bubblified.zsh-theme
207 lines (169 loc) · 7.19 KB
/
bubblified.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
# vim:ft=sh
# Bubble Theme
# Inspired by bubblewritten and agnoster
# written by hohmannr
# SYMBOL CONSTANTS
blub_left=''
blub_right=''
prompt_symbol='-->'
user_symbol='%n'
user_machine_symbol=' גּ '
machine_symbol='%M'
filepath_symbol='%~'
git_branch_symbol=''
git_clean_symbol=''
git_modified_symbol='•'
git_added_symbol=''
git_deleted_symbol=''
git_renamed_symbol=''
git_untracked_symbol='裸'
git_copied_symbol=''
git_unmerged_symbol='!'
git_stashed_symbol=''
ssh_symbol='ssh'
# COLOR CONSTANTS
# NOTE: Possible values include zsh-color-strings like 'red', 'black', 'magenta' etc. Aswell as zsh-color-codes which you can list with the command 'spectrum_ls', e.g. '078' for the 78th color code.
bubble_color='black'
prompt_symbol_color='blue'
prompt_symbol_error_color='red'
user_color='yellow'
user_machine_symbol_color='green'
machine_color='magenta'
filepath_color='blue'
git_clean_color='green'
git_unstaged_color='yellow'
git_staged_color='magenta'
git_stashed_color='blue'
git_unmerged_color='red'
git_symbols_color='black'
ssh_symbol_color='black'
ssh_bubble_color='green'
# HELPER FUNCTIONS
bubblify () {
# This is a helper function to build custom bubbles.
#
# ARGS VALUES DESC
# ---- ------ ----
# 1. {0, 1, 2, 3} 0: build left side bubble: content█
# 1: build right side bubble: █content
# 2: build middle part: █content█
# 3: build custom colored whole bubble: content
#
# 2. string content to be displayed in partial bubble
#
# 3. {'red', '073' ...} foreground color (text color) as zsh-color-string or zsh-color-code
#
# 4. {'red', '073' ...} background color (bubble segment color) as zsh-color-string or zsh-color-code
if [[ $1 -eq 0 ]]; then
echo -n "$(foreground $4)$blub_left$(foreground $3)$(background $4)$2%{$reset_color%}"
elif [[ $1 -eq 1 ]]; then
echo -n "$(foreground $3)$(background $4)$2%{$reset_color%}"
elif [[ $1 -eq 2 ]]; then
echo -n "$(foreground $3)$(background $4)$2%{$reset_color%}$(foreground $4)$blub_right%{$reset_color%}"
elif [[ $1 -eq 3 ]]; then
echo -n "$(foreground $4)$blub_left$(foreground $3)$(background $4)$2%{$reset_color%}$(foreground $4)$blub_right%{$reset_color%}"
else
echo -n 'bblfy_fail'
fi
}
foreground () {
# Helper function for 256 color support beyond basic color terms such as 'black', 'red' ...
if [[ $1 =~ '[0-9]{3}' && $1 -le 255 && $1 -ge 0 ]]; then
echo -n "%{$FG[$1]%}"
else
echo -n "%{$fg[$1]%}"
fi
}
background () {
# Helper function for 256 color support beyond basic color terms such as 'black', 'red' ...
if [[ $1 =~ '[0-9]{3}' && $1 -le 255 && $1 -ge 0 ]]; then
echo "%{$BG[$1]%}"
else
echo "%{$bg[$1]%}"
fi
}
# PROMPT FUNCTIONS
git_bubble () {
# This parses 'git status -s' to retrieve all necessary information...I am new to this zsh scripting...mercy!
local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ -n $git_branch ]]; then
# branch name with symbol, initialize symbols and git status output
local git_info="$git_branch_symbol $git_branch"
local git_symbols=""
local git_status=$(git status -s 2> /dev/null | awk '{print substr($0,1,2)}')
# used for coloring (and some for icons)
local git_unmerged=$(grep -m1 -E -- 'U|DD|AA' <<< $git_status)
local git_branch_stashed=$(git stash list | grep $git_branch)
local git_unstaged=$(echo -n $git_status | awk '{print substr($0,2,1)}')
# used for icons
local git_not_clean=$git_status
local git_modified=$(grep -m1 'M' <<< $git_status)
local git_added=$(grep -m1 'A' <<< $git_status)
local git_deleted=$(grep -m1 'D' <<< $git_status)
local git_untracked=$(grep -m1 '??' <<< $git_status)
local git_renamed=$(grep -m1 'R' <<< $git_status)
local git_copied=$(grep -m1 'C' <<< $git_status)
# coloring
if [[ -n $git_unmerged ]]; then
local git_color=$git_unmerged_color
git_symbols="$git_symbols$git_unmerged_symbol"
elif [[ -n $git_branch_stashed ]]; then
local git_color=$git_stashed_color
git_symbols="$git_symbols$git_stashed_symbol"
elif [[ -n "${git_unstaged//[$' \t\r\n']}" && -n $git_not_clean ]]; then
local git_color=$git_unstaged_color
elif [[ -z "${git_unstaged//[$' \t\r\n']}" && -n $git_not_clean ]]; then
local git_color=$git_staged_color
else
local git_color=$git_clean_color
git_symbols="$git_symbols$git_clean_symbol"
fi
# icons
if [[ -n $git_modified ]]; then
git_symbols="$git_symbols$git_modified_symbol"
fi
if [[ -n $git_added ]]; then
git_symbols="$git_symbols$git_added_symbol"
fi
if [[ -n $git_deleted ]]; then
git_symbols="$git_symbols$git_deleted_symbol"
fi
if [[ -n $git_untracked ]]; then
git_symbols="$git_symbols$git_untracked_symbol"
fi
if [[ -n $git_renamed ]]; then
git_symbols="$git_symbols$git_renamed_symbol"
fi
if [[ -n $git_copied ]]; then
git_symbols="$git_symbols$git_copied_symbol"
fi
echo -n "$(bubblify 0 "$git_info " $git_color $bubble_color)$(bubblify 2 " $git_symbols" $git_symbols_color $git_color) "
fi
}
ssh_bubble () {
# detects an ssh connection and displays a bubble
if [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION ]]; then
echo -n "$(bubblify 3 "$ssh_symbol" $ssh_symbol_color $ssh_bubble_color) "
fi
}
# DEFAULT PROMPT BUILDING BLOCKS
bubble_left="$(foreground $bubble_color)$blub_left%{$reset_color%}$(background $bubble_color)"
bubble_right="%{$reset_color%}$(foreground $bubble_color)$blub_right%{$reset_color%} "
end_of_prompt_bubble="$bubble_left%(?,$(foreground $prompt_symbol_color)$prompt_symbol,$(foreground $prompt_symbol_error_color)$prompt_symbol)$bubble_right"
end_of_prompt=" %(?,$(foreground $prompt_symbol_color)$prompt_symbol,$(foreground $prompt_symbol_error_color)$prompt_symbol%{$reset_color%}) "
user_machine_bubble="$bubble_left$(foreground $user_color)$user_symbol$(foreground $user_machine_symbol_color)$user_machine_symbol$(foreground $machine_color)$machine_symbol$bubble_right"
filepath_bubble="$bubble_left$(foreground $filepath_color)$filepath_symbol$bubble_right"
error_code_bubble="%(?,,$bubble_left$(foreground $prompt_symbol_error_color)%?$bubble_right)"
# PROMPTS
# different prompts to try out, just uncomment/comment
# --- 1 ---
#PROMPT='$(ssh_bubble)$user_machine_bubble$filepath_bubble$(git_bubble)'
# --- 2 ---
#PROMPT='$end_of_prompt_bubble'
#RPROMPT='$(ssh_bubble)$filepath_bubble$(git_bubble)$error_code_bubble'
# --- 3 ---
_newline=$'\n'
_lineup=$'\e[1A'
_linedown=$'\e[1B'
PROMPT='$(ssh_bubble)$user_machine_bubble$filepath_bubble$_newline$end_of_prompt%{$reset_color%}'
RPROMPT='%{$_lineup%}$(git_bubble)$error_code_bubble%{$_linedown%}%{$reset_color%}'