Last active
August 29, 2015 13:56
-
-
Save d11wtq/9248289 to your computer and use it in GitHub Desktop.
Revisions
-
d11wtq revised this gist
Feb 27, 2014 . 1 changed file with 46 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,34 +3,68 @@ TTY=/dev/tty spin() { width=20 delta=1 #fwd_chars=("\\" "|" "/" "-") #rev_chars=("/" "|" "\\" "-") fwd_chars=">" rev_chars="<" space=0 "$@" >/dev/null & pid=$! tput civis while kill -0 $pid 2>/dev/null do if ((delta>0)) then chars=(${fwd_chars[@]}) else chars=(${rev_chars[@]}) fi # make a line of dashes for ((i=0; i<width; i++)) do echo -ne "-" >$TTY done # move to the right offset for ((i=0; i<width-space; i++)) do echo -ne "\b" >$TTY done # animate for c in ${chars[@]} do echo -ne "$c" >$TTY sleep 0.075 echo -ne "\b" >$TTY done # move back to the left for ((i=0; i<space; i++)) do echo -ne "\b" >$TTY done # clear the line for ((i=0; i<width; i++)) do echo -ne " " >$TTY done # back to the left for ((i=0; i<width; i++)) do echo -ne "\b" >$TTY done ((space+=delta)) if ((space>=width)) then delta=-1 ((space+=delta)) @@ -42,12 +76,9 @@ spin() { ((space+=delta)) fi done tput cnorm wait $pid } spin sleep 15 echo "Done." -
d11wtq created this gist
Feb 27, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ #!/bin/bash TTY=/dev/tty spin() { width=5 delta=1 "$@" >/dev/null & child=$! chars=("\\" "|" "/" "-") space=0 while kill -0 $child 2>/dev/null do for ((i=0; i<space; i++)) do echo -ne " " >$TTY done for c in ${chars[@]} do echo -ne "$c" >$TTY sleep 0.1 echo -ne "\b" >$TTY done for ((i=0; i<space; i++)) do echo -ne "\b" >$TTY done ((space+=delta)) if ((space>width)) then delta=-1 ((space+=delta)) ((space+=delta)) elif ((space<0)) then delta=1 ((space+=delta)) ((space+=delta)) fi done wait $child } example() { sleep 5 } spin example echo "Done."