File tree 2 files changed +102
-0
lines changed
2 files changed +102
-0
lines changed Original file line number Diff line number Diff line change @@ -783,3 +783,15 @@ func_secret_input(){
783
783
echo " "
784
784
}
785
785
786
+
787
+ # Check if a program is installed
788
+ command_exists () {
789
+ # check if command exists and fail otherwise
790
+ command -v " $1 " > /dev/null 2>&1
791
+ if [[ $? -ne 0 ]]; then
792
+ echo " I require $1 but it's not installed. Abort."
793
+ exit 1
794
+ fi
795
+ }
796
+
797
+
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Shows a spinner while another command is running. Randomly picks one of 12 spinner styles.
3
+ # @args command to run (with any parameters) while showing a spinner.
4
+ # E.g. ‹spinner sleep 10›
5
+
6
+ function shutdown() {
7
+ tput cnorm # reset cursor
8
+ }
9
+ trap shutdown EXIT
10
+
11
+ function cursorBack() {
12
+ echo -en " \033[$1 D"
13
+ }
14
+
15
+ function spinner() {
16
+ # make sure we use non-unicode character type locale
17
+ # (that way it works for any locale as long as the font supports the characters)
18
+ local LC_CTYPE=C
19
+
20
+ local pid=$1 # Process Id of the previous running command
21
+
22
+ case $(( $RANDOM % 12 )) in
23
+ 0)
24
+ local spin=' ⠁⠂⠄⡀⢀⠠⠐⠈'
25
+ local charwidth=3
26
+ ;;
27
+ 1)
28
+ local spin=' -\|/'
29
+ local charwidth=1
30
+ ;;
31
+ 2)
32
+ local spin=" ▁▂▃▄▅▆▇█▇▆▅▄▃▂▁"
33
+ local charwidth=3
34
+ ;;
35
+ 3)
36
+ local spin=" ▉▊▋▌▍▎▏▎▍▌▋▊▉"
37
+ local charwidth=3
38
+ ;;
39
+ 4)
40
+ local spin=' ←↖↑↗→↘↓↙'
41
+ local charwidth=3
42
+ ;;
43
+ 5)
44
+ local spin=' ▖▘▝▗'
45
+ local charwidth=3
46
+ ;;
47
+ 6)
48
+ local spin=' ┤┘┴└├┌┬┐'
49
+ local charwidth=3
50
+ ;;
51
+ 7)
52
+ local spin=' ◢◣◤◥'
53
+ local charwidth=3
54
+ ;;
55
+ 8)
56
+ local spin=' ◰◳◲◱'
57
+ local charwidth=3
58
+ ;;
59
+ 9)
60
+ local spin=' ◴◷◶◵'
61
+ local charwidth=3
62
+ ;;
63
+ 10)
64
+ local spin=' ◐◓◑◒'
65
+ local charwidth=3
66
+ ;;
67
+ 11)
68
+ local spin=' ⣾⣽⣻⢿⡿⣟⣯⣷'
69
+ local charwidth=3
70
+ ;;
71
+ esac
72
+
73
+ local i=0
74
+ tput civis # cursor invisible
75
+ while kill -0 $pid 2> /dev/null; do
76
+ local i=$(( (i + $charwidth ) % ${# spin} ))
77
+ printf " %s" " ${spin: $i : $charwidth } "
78
+
79
+ cursorBack 1
80
+ sleep .1
81
+ done
82
+ tput cnorm
83
+ wait $pid # capture exit code
84
+ echo " 123"
85
+ return $?
86
+ }
87
+
88
+ (" $@ " ) &
89
+
90
+ spinner $!
You can’t perform that action at this time.
0 commit comments