Skip to content

Instantly share code, notes, and snippets.

@geoffrepoli
Last active December 13, 2022 15:12
Show Gist options
  • Save geoffrepoli/14966c8e7cd33386b917cc30dd919135 to your computer and use it in GitHub Desktop.
Save geoffrepoli/14966c8e7cd33386b917cc30dd919135 to your computer and use it in GitHub Desktop.
function you can place in your scripts and call on any command where you want progress animations. replaced the earlier snippet that was less plug and play. the characters in $loop can be replaced with other characters - printf prints 3 individual random characters from the string stored in $loop
_progressBar() {
local pid="$1"
if ps -p "$pid" &>/dev/null; then
loop='▁▃▄▅▆▇█'
while kill -0 "$pid" &>/dev/null; do
printf "%b\r" "${loop:$((RANDOM%${#loop})):1}${loop:$((RANDOM%${#loop})):1}${loop:$((RANDOM%${#loop})):1}"
sleep 0.1
done
fi
}
yourcommand &
_progressBar $!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment