-
-
Save anthonygclark/9679966 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
_FAIL="[-]" | |
_SUCCESS="[+]" | |
_NOTE="[*]" | |
function _progress() | |
{ | |
local PID=$1 | |
local msg="$2" | |
local delay=0.25 | |
local str=("/" "-" "\\" "|") | |
local index=0 | |
while kill -0 $PID &>/dev/null; do | |
echo -ne "\r[${str[$index]}] "$msg" " | |
sleep $delay | |
index=$(bc <<< "(($index+1) % ${#str[@]})") | |
done | |
} | |
function _task() | |
{ | |
eval "$1" &> "$logFile" & | |
local pid=$! | |
if [ -t 1 ]; then | |
_progress $pid "$2" | |
else | |
echo -en "\r[...] "$2"" | |
wait $pid | |
fi | |
wait $pid | |
local ret=$? | |
if ! (( $ret )); then | |
echo -en "\r$_SUCCESS "$2" \n" | |
else | |
echo -en "\r$_FAIL "$2" \n" | |
fi | |
return $ret | |
} | |
export logFile=/dev/null | |
_task "sleep 3 && true" "Sleep and true" | |
_task "sleep 3 && false" "Sleep and false" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment