diff options
author | katherine <shmibs@airen-no-jikken.icu> | 2018-12-19 17:35:39 -0700 |
---|---|---|
committer | katherine <shmibs@airen-no-jikken.icu> | 2018-12-19 17:35:39 -0700 |
commit | db947a1f555eab19b87cd540c831d1fc30310025 (patch) | |
tree | 5092b1757671aa384b02625f0e6dc48804b687d9 /.config/init/helpers | |
parent | 5b7c0ef6b8d064685713e76143d89669b0d08f7d (diff) | |
download | dotfiles-db947a1f555eab19b87cd540c831d1fc30310025.tar.gz |
add fancy new functions, with shared helpers
Diffstat (limited to '.config/init/helpers')
-rw-r--r-- | .config/init/helpers | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/.config/init/helpers b/.config/init/helpers new file mode 100644 index 0000000..69963cb --- /dev/null +++ b/.config/init/helpers @@ -0,0 +1,77 @@ +print-error() { + 1>&2 echo "\e[1;31merror:\e[0m $1" +} + +abort() { + print-error $1 + exit 1 +} + +wait-anim() { + [[ $#@ -ne 0 ]] && [[ $#@ -lt 4 ]] || return 1 + + local pidpat='^[1-9][0-9]*$' + local colourpat='^(black|light_black|red|light_red|green|light_green|yellow|light_yellow|blue|light_blue|magenta|light_magenta|cyan|light_cyan|white|light_white)$' + + [[ $1 =~ $pidpat ]] || return 1 + if [[ ! -z $3 ]]; then + [[ $3 =~ $colourpat ]] || return 1 + fi + + local message + local colour + + [[ -z $2 ]] && message='waiting...' || message=$2 + [[ -z $3 ]] && colour='yellow' || colour=$3 + + case $colour in + 'black') colour='\e[30m' ;; + 'light_black') colour='\e[1;30m' ;; + 'red') colour='\e[31m' ;; + 'light_red') colour='\e[1;31m' ;; + 'green') colour='\e[32m' ;; + 'light_green') colour='\e[1;32m' ;; + 'yellow') colour='\e[33m' ;; + 'light_yellow') colour='\e[1;33m' ;; + 'blue') colour='\e[34m' ;; + 'light_blue') colour='\e[1;34m' ;; + 'magenta') colour='\e[35m' ;; + 'light_magenta') colour='\e[1;35m' ;; + 'cyan') colour='\e[36m' ;; + 'light_cyan') colour='\e[1;36m' ;; + 'white') colour='\e[37m' ;; + 'light_white') colour='\e[1;37m' ;; + esac + + local curframe + local frames + + case $(($RANDOM % 7)) in + 0) frames=('▁' '▂' '▃' '▄' '▅' '▆' '▇' '█' '▇' '▆' '▅' '▄' '▃' '▂') ;; + 1) frames=(' ' '▖' '▚' '▝' ' ' '▘' '▞' '▗') ;; + 2) frames=('╀' '╂' '╁' '┼' '┽' '┿' '┾' '┼' '╁' '╂' '╀' '┼' '┾' '┿' '┽' '┼') ;; + 3) frames=('─' '└' '│' '┌' '─' '┐' '│' '┘') ;; + 4) frames=('.' '。' '×' ':' '*' '.' '°' '♪' '×' '♫' '°' '♡') ;; + 5) frames=(' ' ' ' '░' '░' '▒' '▒' '▓' '▓' '█' '█' '▓' '▓' '▒' '▒' '░' '░') ;; + 6) frames=('O' 'o' '.' 'o') ;; + esac + + (while 2>/dev/null kill -0 $1; do + if [[ -z $curframe ]]; then + curframe=0 + printf "\e[s" + else + printf "\e[u\e[K" + fi + printf "|\e[1;32m${frames[$(($curframe + 1))]}\e[0m| $colour$message\e[0m" + curframe=$(( ($curframe + 1) % $#frames )) + sleep .2 + done) & + + # trap "echo -n '\e[G\e[J\e[s'" SIGWINCH + + wait $1 + local r=$? + printf "\e[u\e[K" + return $r +} |