-
Notifications
You must be signed in to change notification settings - Fork 0
/
.AbFab.sh
441 lines (390 loc) · 12.2 KB
/
.AbFab.sh
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/bin/bash
#shellcheck shell=bash
#shellcheck disable=SC2016,SC1083,SC1090,SC2116,SC2154
export AbFab_SCREENSAVER_SELECT=0
export AbFab_SCREENSAVER_IDLE_TIME=45
export AbFab_SCREENSAVER_NOTICE_TIME=3
export AbFab_SCREENSAVER_TIMEOUT=3600
export AbFab_SCREEN_SAVER_DISABLE=false
export AbFab_SCREEN_SAVER_LIST=("cmatrix -bu 4 -a | lolcat -F 0.00015"
"cmatrix -bu 4 -a | lolcat -F 0.0005"
"cmatrix -bu 4 -a"
"nyancat --frames 600"
"asciiquarium" ) # "hollywood -s 6" )
export AbFab_SCREEN_SAVER_PRESHOW_LIST=("sl -Fal | lolcat"
"sl -al | lolcat"
"nyancat --frames 100" ) # randomize the Fal 0..8 -3 bits THis is also only a preexec option it does not loop
export AbFab_EXEC_START_PREFIX='🏳️🌈'
export AbFab_EXEC_END_PREFIX='🏁 '
export AbFab_EXEC_DURATION_PRECISION=4
export AbFab_RUN_DURATION_DISABLE=false
export AbFab_LOLCAT_SEED=1
export AbFab_LOLCAT_INCREMENT=2
export AbFab_LOLCAT_FREQ=0.3
export AbFab_PROMPT_COLOR='rainbow'
export AbFab_ANIMAL_FRIENDS=7 # The Number of friends to show in prompt -1 for random
export AbFab_ANIMAL_FRIENDS_MIN=2
export AbFab_ANIMAL_FRIENDS_MAX=14
export AbFab_ANIMAL_HERD="false"
export AbFab_ANIMAL_PARADE="rotate" # none || rotate || random
export AbFab_ANIMAL_SELECT=0 # Set to 0 for random
export AbFab_ANIMALS=🐒🦍🐕🐩🐈🐅🐆🐴🐎🦄🦓🦌🐂🐃🐄🐖🐗🐏🐑🐐🐪🐫🦙🦒🐘🦏🦛🐁🐀🐇🦔🦇🦘🦡🦃🐔🐓🐣🐤🐥🐦🐧🦅🦆🦢🦉🦚🦜🐊🐢🦎🐍🐲🐉🦕🦖🐳🐋🐬🐟🐠🐡🦈🐙🐚🦀🦞🦐🦑🐌🦋🐛🐜🐝🐞🦗🦂
#🕊🐿🕷 # These had kerning issues with font need monospace emojis
#🌈🏳️🌈
# 🤑👹☠️
# 😺😸😹😻😼😽🙀😿😾
# 🙈🙉🙊🐵🐽
# 🐺🦊🦝🐱🦁🐯🐸🐻🐨🐼🐭🐮🐷🐹🐰🐶
# 🐒🦍🐕🐩🐈
# 🐅🐆🐴🐎🦄🦓🦌🐂🐃🐄
# 🐖🐗🐏🐑🐐🐪🐫🦙🦒🐘🦏🦛
# 🐁🐀🐇🐿🦔🦘🦡
# 🦇
# 🦜🦃🐔🐓🐣🐤🐥🐦🐧🕊🦅🦆🦢🦉🦚
# 🐢🐊🦎🐍🐲🐉🦕🦖
# 🐳🐋🐬🦈🐟🐠🐡🐙🦀🦞🦐🦑
# 🐌🦋🐛🐜🐝🐞🦗🕷🦂
# 🦟🦠
# 🕸🐾🐚
# 🦄🦚🦜
#😀😁😂😃😄😅😆😉😊😋😎😍😘😗😙😚☺🙂😐😑😶😏😣😥😮😯😪😫😴😌😛😜😝😒😓😔😕😲☹🙁😖😞😟😤😢😭😦😧😨😩😬😰😱😳🤪😵😡😠😷😇😈👿💀💩😺😸😹😻😼😽🙀😿😾👨👩👴👵👌👍🤛🏻🤛🏼🤛🏽🤛🏾🤛🏿🤜🏻🤜🏼🤜🏽🤜🏾🤜🏿💦🕶🐵🐒🐶🐺🐱🐯🐴🐮🐷🐭🐹🐰🐻🐨🐼🐥🐸🐍🐲🍜🌚🌛🌜🌝🌞🌬🎃♥🎵💡📄🏁🚩🏳️🌈🏳🏴
#🌿🌽🌶🍞🍟🍕🍲🍚🍜☕🔪
AbFab_ANIMAL_ARRAY=($(eval echo "$AbFab_ANIMALS" | sed "s/./& /g"))
# mapfile -t AbFab_ANIMAL_ARRAY < <($AbFab_ANIMALS)
setopt promptsubst
alias AbFab-SHOW_SETTINGS='export | rg AbFab'
AbFab_fn_DEPENDENCY_LIST() {
export AbFab_DEPENDENCIES=("coreutils"
"tmux"
"cmatrix"
"cowsay"
"lolcat"
"fortune"
"hollywood"
"asciiquarium"
"nyancat" "sl" )
}
AbFab_fn_ANIMAL() {
if [[ $1 -gt 0 ]]; then
export AbFab_ANIMAL_SELECT=$1
else
export AbFab_ANIMAL_SELECT=0
fi
echo "AbFab_ANIMAL_SELECT: $AbFab_ANIMAL_SELECT (Reminder: 0 is random)"
}
AbFab_fn_ANIMAL_FRIENDS_SET_NUM() {
if [[ $1 -ge $AbFab_ANIMAL_FRIENDS_MIN && $1 -le $AbFab_ANIMAL_FRIENDS_MAX ]]; then
AbFab_ANIMAL_FRIENDS=$1
elif [[ $1 -le $AbFab_ANIMAL_FRIENDS_MIN ]]; then
AbFab_ANIMAL_FRIENDS=$AbFab_ANIMAL_FRIENDS_MIN
else
AbFab_ANIMAL_FRIENDS=$AbFab_ANIMAL_FRIENDS_MAX
fi
if [[ $1 -le -1 ]]; then
lo=$AbFab_ANIMAL_FRIENDS_MIN
hi=$AbFab_ANIMAL_FRIENDS_MAX
AbFab_ANIMAL_FRIENDS=$(shuf -i $lo-$hi -n 1)
echo "Randomly Picked : $AbFab_ANIMAL_FRIENDS"
fi
export AbFab_ANIMAL_FRIENDS
}
AbFab_fn_SHOW_ANIMAL_FRIENDS_HERD() {
animal_friends=""
i=0
if [[ "$AbFab_ANIMAL_HERD" = "true" ]]; then
herd_index=$((RANDOM % ${#AbFab_ANIMAL_ARRAY[@]}))
fi
until [[ $i -ge $AbFab_ANIMAL_FRIENDS ]]; do
if [[ "$AbFab_ANIMAL_SELECT" -eq 0 ]]; then
if [[ "$AbFab_ANIMAL_HERD" = "true" ]]; then
idx=$herd_index
else
idx=$((RANDOM % ${#AbFab_ANIMAL_ARRAY[@]}))
fi
animal_friends+=${AbFab_ANIMAL_ARRAY[$idx+1]}
else
animal_friends+=${AbFab_ANIMAL_ARRAY[$AbFab_ANIMAL_SELECT]}
fi
((i++))
done
export animal_friends
echo "$animal_friends"
}
AbFab_fn_GEN_ANIMAL_FRIENDS() {
if [[ "$AbFab_ANIMAL_PARADE" != "rotate" ]]; then
animal_friends=""
i=0
until [[ $i -ge $AbFab_ANIMAL_FRIENDS ]]; do
if [[ "$AbFab_ANIMAL_SELECT" = "0" ]]; then
animal_index=$((RANDOM % ${#AbFab_ANIMAL_ARRAY[@]}))
animal_friends+=${AbFab_ANIMAL_ARRAY[$animal_index+1]}
else
animal_friends+=${AbFab_ANIMAL_ARRAY[$AbFab_ANIMAL_SELECT]}
fi
((i++))
done
else
while [[ ${#animal_friends} -gt $AbFab_ANIMAL_FRIENDS ]]; do
animal_friends=${animal_friends:1}
done
while [[ ${#animal_friends} -lt $AbFab_ANIMAL_FRIENDS ]]; do
animal_index=$((RANDOM % ${#AbFab_ANIMAL_ARRAY[@]}))
animal_friends+=${AbFab_ANIMAL_ARRAY[$animal_index+1]}
done
fi
export animal_friends
}
AbFab_fn_ANIMALS() {
if [[ "$AbFab_ANIMAL_HERD" = "true" ]]; then
AbFab_fn_SHOW_ANIMAL_FRIENDS_HERD "$@"
else
AbFab_fn_GEN_ANIMAL_FRIENDS
echo "$animal_friends"
fi
}
ABFab_fn_rotate() {
animal_friends=${animal_friends:1}
animal_index=$((RANDOM % ${#AbFab_ANIMAL_ARRAY[@]}))
animal_friends+=${AbFab_ANIMAL_ARRAY[$animal_index+1]}
}
AbFab_fn_RAINBOW() {
lolcat -f -F $AbFab_LOLCAT_FREQ -S $AbFab_LOLCAT_SEED
}
AbFab_fn_COLOR() { #TODO:This needs to be completed, single color prompt not working
if [[ "$1" != "" ]]; then
echo '%{$fg['"$1"']%}'
else
echo '%{$fg[$AbFab_PROMPT_COLOR]%}'
fi
}
AbFab_fn_RAINBOW_INC() {
AbFab_fn_RAINBOW
((AbFab_LOLCAT_SEED += AbFab_LOLCAT_INCREMENT))
}
AbFab_fn_SHOW_ALL_ANIMAL_NUMBERS() {
out='Animals with Numbers:\n'
for (( x = 1; x <= $#AbFab_ANIMAL_ARRAY; x++ ))
do
out+="$x ${AbFab_ANIMAL_ARRAY[$x]} "
done
echo "$out" | AbFab_fn_RAINBOW_INC
}
AbFab_fn_SHOW_ALL_ANIMALS() {
echo $AbFab_ANIMALS
}
AbFab_fn_SHOW_ANIMAL() {
if [[ $1 -gt 0 ]]; then
echo "$1 is ${AbFab_ANIMAL_ARRAY[$1]}" | AbFab_fn_RAINBOW_INC
else
echo "Please enter a number to see that animal, but here they all are."
AbFab_SHOW_ALL_ANIMAL_NUMBERS "$@"
fi
}
__prev_cmd() {
cmd_hist=$HISTCMD && ((cmd_hist-=1))
cmd="${history[$cmd_hist]}"
return "$cmd"
}
AbFab_fn_DURATION() {
if [[ -v start_cmd && ! -v AbFab_RUN_DURATION_DISABLE ]]; then
end_cmd=$(AbFab_fn_EXEC_TS)
cmd_dur="$(bc <<<"$end_cmd-$start_cmd")"
printf -v cmd_dur "%.${AbFab_EXEC_DURATION_PRECISION}f" "$cmd_dur"
# echo ${TERM_BLUE}"Duration: ${cmd_dur}"${TERM_DEFAULT} | AbFab_fn_RAINBOW_INC
prev_hist=$HISTCMD && ((prev_hist-=1))
prev=$(echo "${history[$prev_hist]}")
fin=$(echo "$AbFab_EXEC_END_PREFIX" "$(get_date_blink_colon)" Duration "$cmd_dur" - "$prev" | AbFab_fn_RAINBOW_INC )
echo "$fin"
done=""
if [ "$__exit" -ne 0 ]; then
done+="🚩"
fi
done+="${cmd_dur}[$__exit]🏁${prev}🏁(${prev_hist})"
AbFab_fn_TERM_TITLE "$done"
unset start_cmd; unset end_cmd; unset cmd_dur
fi
}
AbFab_fn_EXEC_TS() {
date -u +%s.%N
}
AbFab_fn_START_EXEC() {
if [[ ! -v AbFab_RUN_DURATION_DISABLE ]]; then
start_cmd=$(AbFab_fn_EXEC_TS)
#echo "$AbFab_EXEC_START_PREFIX $(get_date_blink_colon)-Run Start from: $(pwd)" | AbFab_fn_RAINBOW_INC
fi
}
AbFab_fn_TERM_TITLE() { printf "\033]0;%s\007" "$*"; }
AbFab_fn_START_TITLE() {
cmd=""
if [[ "$1" != "" ]]; then
cmd=$1
else
cmd_hist=$HISTCMD && ((prev_hist-=1))
cmd=$(echo "${history[$cmd_hist]}")
fi
start_run=$(echo "🏳️🌈 $(get_date_blink_colon) Started: $cmd" | AbFab_fn_RAINBOW_INC )
echo "$start_run"
AbFab_fn_TERM_TITLE "🏳️🌈 $cmd_hist Started Running : $cmd"
}
preexec() {
AbFab_fn_START_TITLE
AbFab_fn_START_EXEC
}
AbFab_fn_COUNTDOWN () {
i="$1"
while [ "$i" -ge 0 ]; do
printf "\rStarting in %s seconds." "$i" | AbFab_fn_RAINBOW
((i -= 1))
sleep 1
done
printf '\nStarting now.\n' | AbFab_fn_RAINBOW_INC
}
AbFab_fn_SCREENSAVER() {
prev_scr=124
while [[ "$prev_scr" -eq 124 ]]; do
screen_saver_on="true"
ind=$1
timeout=$2
if [[ "$ind" -eq 0 ]]; then
printf "\nRandomly selecting screen saver. Iteractively, provide a number to choose specific screensaver.\n" | AbFab_fn_RAINBOW_INC
ind=$((RANDOM % ${#AbFab_SCREEN_SAVER_LIST[@]} + 1))
fi
chosen=${AbFab_SCREEN_SAVER_LIST[$ind]}
echo "$(get_date) Starting the chosen one: ${chosen}" | AbFab_fn_RAINBOW_INC
AbFab_fn_COUNTDOWN $AbFab_SCREENSAVER_NOTICE_TIME
AbFab_fn_START_TITLE "$chosen"
AbFab_fn_START_EXEC
#TODO Add pre show screen saver option
if [[ "$timeout" -eq 0 ]]; then
eval "$chosen"
else
timeout_cmd="timeout ${timeout}s $chosen"
eval "$timeout_cmd"
prev_scr=$?
fi
AbFab_fn_DURATION
START=$SECONDS+$AbFab_SCREENSAVER_IDLE_TIME
done
}
if [ -f ~/scripts/.git_prompt.sh ]; then
. ~/scripts/.git_prompt.sh
fi
function parse_git_branch() {
__git_ps1 "(%s)"
}
function parse_git_user() {
git config user.name
}
function parse_git_set_info() {
GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWDIRTYSTATE
gb=$(parse_git_branch)
if [ "" = "$gb" ]; then
echo "" # No git branch
else
echo " $(parse_git_user)-$gb"
fi
}
function get_work_dir() {
wdir='('
wdir+=$(print -P '%~')
wdir+=')'
echo "$wdir"
}
function get_date() {
date +"%a %F %T.%3N"
}
function get_date_blink_colon() {
bcl=$(tput blink):$(tput sgr0)
get_date | sed "s/:/$bcl/g"
}
function get_prev_result() {
pr=$__DEFAULT_LITERAL
pr+='['
pr+='$('
pr+='if [ "$__exit" -eq 0 ]; then '
pr+="echo '$__GREEN_LITERAL'; "
pr+='else '
pr+="echo '$__RED_LITERAL'; fi"
pr+=')'
pr+='$__exit'
pr+=$__DEFAULT_LITERAL
pr+='] '
echo "$pr"
}
function get_random() {
echo $((RANDOM))
}
function get_abfab_animals() {
AbFab_fn_SHOW_ANIMAL_FRIENDS_RETURN "$(get_random)"
}
function get_animals_rev() {
AbFab_fn_ANIMALS "$@" | rev
}
function get_animals_fwd() {
AbFab_fn_ANIMALS "$@"
}
precmd_functions+=('__prompt_command')
# precmd_functions=('__prompt_command' "${precmd_functions[@]}") # this is to prepend
AbFab_fn_COLORIZE='__abfab'
__prompt_command() {
__exit=$? # Save last exit code
AbFab_fn_DURATION
AbFab_fn_GEN_ANIMAL_FRIENDS
((AbFab_LOLCAT_SEED += AbFab_LOLCAT_INCREMENT))
START=$SECONDS
}
TERM_DEFAULT=$(tput sgr0)
TERM_RED=$(tput setaf 1)
TERM_GREEN=$(tput setaf 2)
ESC=$'\033'
SOH=%{
STX=%}
__DEFAULT_LITERAL=$SOH$TERM_DEFAULT$STX
__RED_LITERAL=$SOH$TERM_RED$STX
__GREEN_LITERAL=$SOH$TERM_GREEN$STX
PS1=$(get_prev_result)
#Seperate Rainbow per section ( date, path, git, etc )
# PS1+='$(eval "$AbFab_fn_COLORIZE" <<<$(get_date))'
# PS1+=' $(eval "$AbFab_fn_COLORIZE" <<<"(\w)")'
# PS1+=' $(eval "$AbFab_fn_COLORIZE" <<<$(parse_git_set_info))'
#Single Rainbow with blinking colons
PS1+='$(eval "$AbFab_fn_COLORIZE" <<< "$(get_animals_fwd)$(get_date_blink_colon)$(get_animals_rev)$(parse_git_set_info)($(print -P "%~"))!>")'
__remove_newline() {
tr -d '\n'
}
__color_wrap_non_printing() {
local REGEX=$ESC'\[[[:digit:];]*m'
local REPLACE=$SOH'&'$STX
sed "s/$REGEX/$REPLACE/g"
}
__collapse_non_printing() {
sed -E "s/$SOH/%{/g" -E "s/$STX/%}/g"
}
__abfab() {
if [[ "$AbFab_PROMPT_COLOR" = "rainbow" ]]; then
AbFab_fn_RAINBOW | __color_wrap_non_printing
else
AbFab_fn_COLOR $AbFab_PROMPT_COLOR | __color_wrap_non_printing
fi
}
TRAPALRM () {
if [ $((SECONDS-START)) -ge $AbFab_SCREENSAVER_IDLE_TIME ]; then
if [[ ! -v AbFab_SCREEN_SAVER_DISABLE && ! -v screen_saver_on ]]; then
AbFab_fn_SCREENSAVER $AbFab_SCREENSAVER_SELECT $AbFab_SCREENSAVER_TIMEOUT # randomly selects by default
fi
else
unset screen_saver_on
fi
if [[ "$AbFab_ANIMAL_HERD" = "false" ]]; then
if [[ "$AbFab_ANIMAL_PARADE" = "random" ]]; then
get_animals_fwd "" > /dev/null 2>&1 # |& /dev/null
else
if [[ "$AbFab_ANIMAL_PARADE" = "rotate" ]]; then
ABFab_fn_rotate
fi
fi
fi
zle reset-prompt
}
TMOUT=1