-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfish_right_prompt.fish
More file actions
248 lines (235 loc) · 9.09 KB
/
Copy pathfish_right_prompt.fish
File metadata and controls
248 lines (235 loc) · 9.09 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
###############################################################################
#
# Prompt theme name:
# dangerous
#
# Description:
# a sophisticated theme
#
# Author:
# Joseph Tannhuber <sepp.tannhuber@yahoo.de>
#
# Sections:
# -> Functions
# -> Toggle functions
# -> Command duration segment
# -> Git segment
# -> PWD segment
# -> Prompt
#
###############################################################################
###############################################################################
# => Functions
###############################################################################
#####################
# => Toggle functions
#####################
function __dangerous_toggle_symbols -d 'Toggles style of symbols, press # in NORMAL or VISUAL mode'
if [ $symbols_style = 'symbols' ]
set symbols_style 'numbers'
else
set symbols_style 'symbols'
end
set pwd_hist_lock true
commandline -f repaint
end
function __dangerous_toggle_pwd -d 'Toggles style of pwd segment, press space bar in NORMAL or VISUAL mode'
for i in (seq (count $dangerous_pwdstyle))
if [ $dangerous_pwdstyle[$i] = $pwd_style ]
set pwd_style $dangerous_pwdstyle[(expr $i \% (count $dangerous_pwdstyle) + 1)]
set pwd_hist_lock true
commandline -f repaint
break
end
end
end
#############################
# => Command duration segment
#############################
function __dangerous_cmd_duration -d 'Displays the elapsed time of last command'
set_color normal
set -l seconds ''
set -l minutes ''
set -l hours ''
set -l days ''
set -l cmd_duration (expr $CMD_DURATION / 1000)
if [ $cmd_duration -gt 0 ]
set seconds (expr $cmd_duration \% 68400 \% 3600 \% 60)'s'
if [ $cmd_duration -ge 60 ]
set minutes (expr $cmd_duration \% 68400 \% 3600 / 60)'m'
if [ $cmd_duration -ge 3600 ]
set hours (expr $cmd_duration \% 68400 / 3600)'h'
if [ $cmd_duration -ge 68400 ]
set days (expr $cmd_duration / 68400)'d'
end
end
end
set_color $dangerous_colors[3]
echo -n '❮'
switch $pwd_style
case short long
if [ $last_status -ne 0 ]
echo -n (set_color $dangerous_colors[7])' '$days$hours$minutes$seconds(set_color $dangerous_colors[3])' ❮'
else
echo -n (set_color $dangerous_colors[12])' '$days$hours$minutes$seconds(set_color $dangerous_colors[3])' ❮'
end
end
end
end
################
# => Git segment
################
function __dangerous_is_git_ahead_or_behind -d 'Check if there are unpulled or unpushed commits'
command git rev-list --count --left-right 'HEAD...@{upstream}' 2> /dev/null | sed 's|\s\+|\n|g'
end
function __dangerous_git_status -d 'Check git status'
set -l git_status (command git status --porcelain 2> /dev/null | cut -c 1-2)
set -l added (echo -sn $git_status\n | egrep -c "[ACDMT][ MT]|[ACMT]D")
set -l deleted (echo -sn $git_status\n | egrep -c "[ ACMRT]D")
set -l modified (echo -sn $git_status\n | egrep -c ".[MT]")
set -l renamed (echo -sn $git_status\n | egrep -c "R.")
set -l unmerged (echo -sn $git_status\n | egrep -c "AA|DD|U.|.U")
set -l untracked (echo -sn $git_status\n | egrep -c "\?\?")
echo -n $added\n$deleted\n$modified\n$renamed\n$unmerged\n$untracked
end
function __dangerous_is_git_stashed -d 'Check if there are stashed commits'
command git log --format="%gd" -g $argv 'refs/stash' -- 2> /dev/null | wc -l | tr -d '[:space:]'
end
function __dangerous_prompt_git_symbols -d 'Displays the git symbols'
set -l is_repo (command git rev-parse --is-inside-work-tree 2> /dev/null)
if [ -z $is_repo ]
return
end
set -l git_ahead_behind (__dangerous_is_git_ahead_or_behind)
set -l git_status (__dangerous_git_status)
set -l git_stashed (__dangerous_is_git_stashed)
if [ (expr $git_status[1] + $git_status[2] + $git_status[3] + $git_status[4] + $git_status[5] + $git_status[6] + $git_stashed) -ne 0 ]
set_color $dangerous_colors[4]
echo -n '❮'
switch $pwd_style
case long short
if [ $symbols_style = 'symbols' ]
if [ (count $git_ahead_behind) -eq 2 ]
if [ $git_ahead_behind[1] -gt 0 ]
set_color -o $dangerous_colors[5]
echo -n ' ↑'
end
if [ $git_ahead_behind[2] -gt 0 ]
set_color -o $dangerous_colors[5]
echo -n ' ↓'
end
end
if [ $git_status[1] -gt 0 ]
set_color -o $dangerous_colors[12]
echo -n ' +'
end
if [ $git_status[2] -gt 0 ]
set_color -o $dangerous_colors[7]
echo -n ' –'
end
if [ $git_status[3] -gt 0 ]
set_color -o $dangerous_colors[10]
echo -n ' ✱'
end
if [ $git_status[4] -gt 0 ]
set_color -o $dangerous_colors[8]
echo -n ' →'
end
if [ $git_status[5] -gt 0 ]
set_color -o $dangerous_colors[9]
echo -n ' ═'
end
if [ $git_status[6] -gt 0 ]
set_color -o $dangerous_colors[4]
echo -n ' ●'
end
if [ $git_stashed -gt 0 ]
set_color -o $dangerous_colors[11]
echo -n ' ✭'
end
else
if [ (count $git_ahead_behind) -eq 2 ]
if [ $git_ahead_behind[1] -gt 0 ]
set_color $dangerous_colors[5]
echo -n ' '$git_ahead_behind[1]
end
if [ $git_ahead_behind[2] -gt 0 ]
set_color $dangerous_colors[5]
echo -n ' '$git_ahead_behind[2]
end
end
if [ $git_status[1] -gt 0 ]
set_color $dangerous_colors[12]
echo -n ' '$git_status[1]
end
if [ $git_status[2] -gt 0 ]
set_color $dangerous_colors[7]
echo -n ' '$git_status[2]
end
if [ $git_status[3] -gt 0 ]
set_color $dangerous_colors[10]
echo -n ' '$git_status[3]
end
if [ $git_status[4] -gt 0 ]
set_color $dangerous_colors[8]
echo -n ' '$git_status[4]
end
if [ $git_status[5] -gt 0 ]
set_color $dangerous_colors[9]
echo -n ' '$git_status[5]
end
if [ $git_status[6] -gt 0 ]
set_color $dangerous_colors[4]
echo -n ' '$git_status[6]
end
if [ $git_stashed -gt 0 ]
set_color $dangerous_colors[11]
echo -n ' '$git_stashed
end
end
set_color normal
echo -n (set_color $dangerous_colors[4])' ❮'
end
end
end
################
# => PWD segment
################
function __dangerous_prompt_pwd -d 'Displays the present working directory'
set_color normal
set -l user_host ' '
if set -q SSH_CLIENT
if [ $symbols_style = 'symbols' ]
switch $pwd_style
case short
set user_host " $USER@"(hostname -s)':'
case long
set user_host " $USER@"(hostname -f)':'
end
else
set user_host " $USER@"(hostname -i)':'
end
end
set_color $dangerous_current_bindmode_color
if [ (count $dangerous_prompt_error) != 1 ]
switch $pwd_style
case short
echo -n '❮'$user_host(prompt_pwd)' '
case long
echo -n '❮'$user_host(pwd)' '
end
else
echo -n "❮ $dangerous_prompt_error "
set -e dangerous_prompt_error[1]
end
set_color $dangerous_current_bindmode_color
echo -n '❮'
set_color normal
end
###############################################################################
# => Prompt
###############################################################################
function fish_right_prompt -d 'Write out the right prompt of the dangerous theme'
echo -n -s (__dangerous_cmd_duration) (__dangerous_prompt_git_symbols) (__dangerous_prompt_pwd)
set_color normal
end