show_spinner()
renders a spinner and prints “Done” after a process has ended.
show_spinner() {
local pid=$1
local spin='-\|/'
local i=0
while kill -0 "$pid" 2>/dev/null; do
i=$(( (i+1) % 4 ))
printf "\r${spin:i:1}"
sleep 0.1
done
printf "\rDone! \n" # Clear the spinner after done
}
Usage
# Example usage: Run a long command in the background
sleep 5m & # Replace with your long-running command
pid=$!
# Call the spinner function
show_spinner "$pid"