Skip to content

Instantly share code, notes, and snippets.

@anthonygclark
Last active August 29, 2015 13:57
Show Gist options
  • Save anthonygclark/9679966 to your computer and use it in GitHub Desktop.
Save anthonygclark/9679966 to your computer and use it in GitHub Desktop.
#!/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