Skip to content

Instantly share code, notes, and snippets.

@davlgd
Created August 20, 2023 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davlgd/6d0e06366b746f33ca6b9f2cdd38a3d4 to your computer and use it in GitHub Desktop.
Save davlgd/6d0e06366b746f33ca6b9f2cdd38a3d4 to your computer and use it in GitHub Desktop.
Spinner for Shell commands
#!/bin/bash
spinner() {
local pid=$1
local delay=0.1
local spinstr="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
local i=0
local len=${#spinstr}
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
i=$(( (i+1) % len ))
char=${spinstr:$i:1}
printf "\r%s Executing long command..." "$char"
sleep $delay
done
# Clear the entire line before printing "Done!"
printf "\r%b" " "
printf "\r"
}
# Usage example
long_command() {
sleep 10
}
printf " Executing long command..."
long_command &
spinner $!
echo -e "\033[32m✓\033[0m Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment