File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -39,23 +39,24 @@ snake_spinner() {
3939 local frames=(' ⣾' ' ⣽' ' ⣻' ' ⢿' ' ⡿' ' ⣟' ' ⣯' ' ⣷' )
4040 local col_arr=(" $CYAN " " $BLUE " " $PURPLE " " $CYAN " " $BLUE " " $PURPLE " " $CYAN " " $BLUE " )
4141 local nf=${# frames[@]}
42- local ncol=${# col_arr[@]}
4342 local i=0 step=0
44- local delay=0.08
45- local elapsed= " 0.0 "
43+ # 0.1s delay → 10 steps = 1s; use pure bash integer math (no bc fork)
44+ local delay=0.1
4645
4746 while true ; do
48- if [ " $pid " -ne 0 ] && ! ps -p " $pid " > /dev/null 2>&1 ; then
47+ # kill -0 is a bash builtin — no subprocess fork unlike ps -p
48+ if [ " $pid " -ne 0 ] && ! kill -0 " $pid " 2> /dev/null; then
4949 break
5050 fi
5151
52+ local secs=$(( step / 10 ))
53+ local tenths=$(( step % 10 ))
5254 local c=" ${col_arr[$i]} "
53- printf " \r${c}${frames[$i]}${NC} ${WHITE}${label}${NC}${GRAY} ...${NC} ${DIM} (${elapsed } s)${NC} "
55+ printf " \r${c}${frames[$i]}${NC} ${WHITE}${label}${NC}${GRAY} ...${NC} ${DIM} (${secs} . ${tenths } s)${NC} "
5456
5557 sleep " $delay "
5658 i=$(( (i + 1 ) % nf ))
5759 step=$(( step + 1 ))
58- elapsed=$( echo " scale=1; $step * $delay " | bc)
5960 done
6061 printf " \r${GREEN} ✓${NC} ${WHITE} Done!${NC} \n"
6162}
You can’t perform that action at this time.
0 commit comments