Friday, May 23, 2008

Waiting cursor function

When you want to animate a sleep in a shell script you can use the following function:
waiting_cursor()
{
echo "In 5 seconds ..., cancel with CTRL-C"
sleep 5
pid=$!
printf "Waiting: |"
rotate='|/-\'
while kill -n 0 $pid 2>/dev/null;
do
rotate="${rotate#?}${rotate%???}"
printf '\b%.1s' "$rotate"
sleep 1
done
echo " "
wait $pid
echo " "
}

No comments:

Post a Comment

comment