-
-
Save sqwxl/a24683a9d5a13356db8b2801ecd94156 to your computer and use it in GitHub Desktop.
Simple bash spinner
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 | |
# source this file in your scripts and use as so: | |
# <command> & spin "Text to display while command is running" | |
function spin() { | |
local tag="$1" | |
local pid=$! # get the pid of the last background process | |
local sp="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏" | |
local i=1 | |
while kill -0 $pid &>/dev/null; do | |
printf "\r\e[0;32m${sp:i++%${#sp}:1}\e[0m $tag" | |
sleep .1 | |
done | |
# wait for the loop to finish | |
if wait $pid &>/dev/null; then | |
printf "\e[0;32m Done!\e[0m\n\n" | |
else | |
printf "\e[0;31m Failed!\e[0m\n\n" | |
exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment