Skip to content

Instantly share code, notes, and snippets.

@itxx00
Created October 19, 2013 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itxx00/7051787 to your computer and use it in GitHub Desktop.
Save itxx00/7051787 to your computer and use it in GitHub Desktop.
progress bar in bash
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