Skip to content

Instantly share code, notes, and snippets.

@iamahuman
Created May 19, 2017 15:54
Show Gist options
  • Save iamahuman/c09ad420ac13c3b5a06e7599fdd6e36d to your computer and use it in GitHub Desktop.
Save iamahuman/c09ad420ac13c3b5a06e7599fdd6e36d to your computer and use it in GitHub Desktop.
(2015) A spinner which you can put on your terminal and waste some time staring at it doing nothing
#!/bin/bash
spin=("|" "/" "-" "\\");((i=j=0,n=$(tput cols)-10))
echo -ne "\r"; tput sc
trap "echo;exit 0" SIGTERM SIGINT SIGHUP
while true;do tput rc;s="\r${spin[$i]} ";k=0;while [[ $k -lt $((j < 0 ? -j - 1 : j)) ]]; do
if [[ $j -ge 0 ]]
then s=$s"=";else s=$s" ";fi;((++k));done;((i++))
if [[ $j -lt 0 ]];then ((--j));else ((++j)); fi; if [ $i -ge ${#spin[@]} ]; then i=0;fi
if [ $j -ge $n ]; then j=-1;else if [ $((-j)) -gt $n ]; then j=0; fi; fi;
printf "$s";sleep 0.05;read -t 0.0001 -n 1 -s ans;if [ "$ans" == "q" ];then break;fi;done;echo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment