Created
December 7, 2012 15:16
-
-
Save resmo/4233873 to your computer and use it in GitHub Desktop.
Progress Bar / Spinnter 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
#!/bin/bash | |
sp="⣾⣽⣻⢿⡿⣟⣯⣷" | |
sp="⠁⠂⠄⡀⢀⠠⠐⠈" | |
#sp="◢ ◣ ◤ ◥" | |
#sp="▉▊▋▌▍▎▏▎▍▌▋▊▉" | |
#sp="▁ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃" | |
progressbar () { | |
local processed=$1 | |
local total=$2 | |
local percentage=$(( $processed * 100 / $total )) | |
printf "\r%3d%% complete " $percentage | |
} | |
spin() { | |
printf "\b${sp:sc++:1} " | |
((sc==${#sp})) && sc=0 | |
} | |
endspin() { | |
printf "\r%s\n" "$@" | |
} | |
sc=0 | |
# do a lot of work | |
for i in {1..2000} | |
do | |
progressbar $i 2000 && spin | |
# do work | |
sleep 0.2 | |
done | |
endspin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment