#!/bin/sh
spinner()
{
local pid=$1
local delay=0.1
local spinners=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
local spinners_count=${#spinners[@]}
local spinstr='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
local infotext=$2
local counter=0
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
let "counter++"
printf "%s %s" ${spinners[$(($counter % $spinners_count))]} "$infotext"
sleep $delay
printf "\b\b\b\b"
for i in $(seq 1 ${#infotext}); do
printf "\b"
done
done
printf " "
for i in $(seq 1 ${#infotext}); do
printf " "
done
printf "\b\b\b\b"
for i in $(seq 1 ${#infotext}); do
printf "\b"
done
}
result=`sleep 10 && echo 123` &
spinner $! "loading..."
echo $result