Skip to content

Instantly share code, notes, and snippets.

@katabame
Created December 8, 2022 15:28
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 katabame/7c0b709824301ac519e7789443bc016e to your computer and use it in GitHub Desktop.
Save katabame/7c0b709824301ac519e7789443bc016e to your computer and use it in GitHub Desktop.
#!/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