Skip to content

Instantly share code, notes, and snippets.

@nirdosh17
Last active September 4, 2019 18:01
Show Gist options
  • Save nirdosh17/53f46454ecfe8504086b9cfbe6e4deba to your computer and use it in GitHub Desktop.
Save nirdosh17/53f46454ecfe8504086b9cfbe6e4deba to your computer and use it in GitHub Desktop.
#!/bin/bash
function progress_bar() {
if [ $1 -eq 0 ];then
comp_p=0
else
COMPLETED=$(($COMPLETED+$STEPS))
comp_p=$(jq -n $1/$ITEM_COUNT*100)
comp_p=$(echo ${comp_p%.*})
fi
x=$(perl -E "say '=' x $COMPLETED")
echo -ne " |" $x" | $comp_p%\r"
}
function loader_init() {
ITEM_COUNT=$1
STEPS=$((100/$ITEM_COUNT))
COMPLETED=0
}
# copy and paste above functions and use it inside a loop as shown below
# pass number of items
loader_init 10
progress_bar 0
for i in $(seq 1 $ITEM_COUNT)
do
# do stuffs here
sleep 0.2
progress_bar $i
done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment