Skip to content

Instantly share code, notes, and snippets.

@zenoamaro
Last active August 29, 2015 14:22
Show Gist options
  • Save zenoamaro/600fabc03607b2e49c71 to your computer and use it in GitHub Desktop.
Save zenoamaro/600fabc03607b2e49c71 to your computer and use it in GitHub Desktop.
Utilities to manipulate the terminal
#!/usr/bin/env bash
set -e
if [[ "$1" == '-h' ]]; then
echo 'Shows a small loading indicator.'
echo "Usage: $(basename $0) [duration=0.15] [frame] [frame...]"
echo
echo 'Example:'
echo " $(basename $0) &; PID=\$!"
echo ' # ...'
echo ' kill $PID'
exit 0
fi
if [[ -n "$1" ]]; then
DURATION="$1"
else
DURATION="0.15"
fi
if [[ -n "$2" ]]; then
CHARACTERS="${@:2}"
else
CHARACTERS="| / - \\"
fi
# Hide the cursor, but take care
# to unhide it if we ^C or exit.
trap "tput cnorm" EXIT
tput civis
while true; do
for C in $CHARACTERS; do
echo "$C"
sleep "$DURATION"
tput cuu1 # Up 1 line
done
done
- loading-spinner
Shows a text-based loading spinner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment