Created
March 13, 2017 18:44
-
-
Save filipekiss/20527d9a8e6817c2582eab3da219bf94 to your computer and use it in GitHub Desktop.
Bash Activity Indicator
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
#!/usr/bin/env bash | |
# | |
# A simple activity indicator for bash scripting. | |
# Optional message can be passed to spinner function. | |
# This can be used on interactive shells and in scripts | |
# | |
# Scripting usage: | |
# | |
# e_spinner "Import MySQL" | |
# cat somefile.sql | mysql > /dev/null | |
# e_spinner_end | |
# | |
# Interactive Shell Usage: | |
# e_spinner_start "Slow running command"; sleep 10; e_spinner_end | |
# | |
e_spinner() { | |
local spinstr='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏' | |
while sleep 0.1; do | |
e_reset_line | |
local temp=${spinstr#?} | |
printf " %s${RESET} ${2}%b${RESET}" "${spinstr:0:1}" "${1}" | |
local spinstr=$temp${spinstr%"$temp"} | |
done | |
} | |
e_spinner_start() { | |
local MESSAGE="$1" | |
e_spinner "$MESSAGE" & | |
E_SPINNER_PID=$! | |
disown $E_SPINNER_PID &> /dev/null #make sure bash doesn't freak out when we kill the spinner | |
} | |
e_spinner_end() { | |
kill $E_SPINNER_PID &> /dev/null | |
e_reset_line | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment