Created
October 19, 2013 04:54
-
-
Save itxx00/7051787 to your computer and use it in GitHub Desktop.
progress bar in bash
This file contains 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 characters
function show_bar() { | |
local i=0;local p=1;local c=">" | |
echo;echo | |
while true;do | |
local x=$(($(tput cols)-3));local y=$(($(tput lines)-2));i=$((i+1)) | |
[ $(($i%$x)) -eq 0 ] && { | |
[ "$c" = ">" ] && c="<" || c=">" | |
} | |
[ "$c" = ">" ] && { | |
p=$((p+1));[ "$p" -ge $x ] && p=$x | |
} | |
[ "$c" = "<" ] && { | |
p=$((p-1));[ "$p" -le 1 ] && p=1 | |
} | |
tput cup $y 1;for ((j=0;j<$x;j++ ));do echo -n "-";done | |
tput cup $y $(($p)); echo -ne "\e[32;49;2m$c\e[0m" | |
tput cup $y $((x+2)); sleep 0.2 | |
done | |
} | |
usage: | |
show_bar & | |
pid=$! | |
trap 'echo you hit Ctrl-C/Ctrl-\, now exiting..; kill $pid; exit' SIGINT SIGQUIT | |
echo sleep now | |
sleep 60 | |
echo sleep done | |
kill $jawsp &>/dev/null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment