Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active January 2, 2016 07:29
Show Gist options
  • Save coderofsalvation/8270372 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8270372 to your computer and use it in GitHub Desktop.
rotating animation for bash
# Usage:
# printf "%s" "[+] tar" && _animrotate $(pidof tar)
#
animrotate()
{ #shows an animation as long as a process is in memory
[ -z "$1" ] && return 1
printf "%s\\n" "$1" | grep -v "[^0-9]" >/dev/null || { printf "%5s\n" ""; return 1; }
_animrotate_var_pid=$1
_animrotate_var_animation_state=1
if [ ! "$(ps -p $_animrotate_var_pid -o comm=)" ]; then
printf "%5s\n" ""
return 1
fi
printf "%s" " "
while [ "$(ps -p $_animrotate_var_pid -o comm=)" ]; do
# rotating star
printf "%b" "\b\b\b"
case $_animrotate_var_animation_state in
1)
printf "%s" "["
printf "%b" "\033[1m|\033[0m"
printf "%s" "]"
_animrotate_var_animation_state=2
;;
2)
printf "%s" "["
printf "%b" "\033[1m/\033[0m"
printf "%s" "]"
_animrotate_var_animation_state=3
;;
3)
printf "%s" "["
printf "%b" "\033[1m-\033[0m"
printf "%s" "]"
_animrotate_var_animation_state=4
;;
4)
printf "%s" "["
printf "%b" "\033[1m"
printf "%s" "\\"
printf "%b" "\033[0m"
printf "%s" "]"
_animrotate_var_animation_state=1
;;
esac
sleep 0.2
done
printf "%b" "\b\b\b\b\b\b\b "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment