Created
December 8, 2022 15:28
-
-
Save katabame/7c0b709824301ac519e7789443bc016e to your computer and use it in GitHub Desktop.
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 | |
BAR_SIZE=40 | |
BAR_CHAR_DONE='#' | |
BAR_CHAR_TODO='-' | |
BAR_PERCENTAGE_SCALE=2 | |
show_progress() { | |
CURRENT=$1 | |
TOTAL=$2 | |
PERCENT=$(awk "BEGIN {printf \"%.1f\", $CURRENT / $TOTAL * 100}") | |
DONE=$(awk "BEGIN {printf \"%.1f\", $BAR_SIZE * $PERCENT / 100}") | |
TODO=$(awk "BEGIN {printf \"%.1f\", $BAR_SIZE - $DONE}") | |
DONE_BAR=$(printf "%${DONE}s" | tr " " "${BAR_CHAR_DONE}") | |
TODO_BAR=$(printf "%${TODO}s" | tr " " "${BAR_CHAR_TODO}") | |
echo -n -e "\rProgress: [${DONE_BAR}${TODO_BAR}] ${PERCENT}%" | |
if [ $TOTAL -eq $CURRENT ]; then | |
echo " DONE" | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment