Skip to content

Instantly share code, notes, and snippets.

@andriitishchenko
Created November 19, 2025 22:13
Show Gist options
  • Select an option

  • Save andriitishchenko/d202bd1751634653d88dec439ae64b71 to your computer and use it in GitHub Desktop.

Select an option

Save andriitishchenko/d202bd1751634653d88dec439ae64b71 to your computer and use it in GitHub Desktop.
Example of bash spinner
#!/bin/bash
spinner() {
local pid=$1
local message="${2}"
local delay=0.1
local spin='-\|/-'
local i=0
while kill -0 "$pid" 2>/dev/null; do
i=$(( (i + 1) % 4 ))
printf "\r[ %c ] ${message}..." "${spin:i:1}" >/dev/tty
sleep "$delay"
done
}
spinwait() {
local pid=$1
local message="${2:-Task}"
spinner $pid "$message" &
local spid=$!
wait $pid
kill $spid 2>/dev/null
printf "\r[ %s ] %s - Done\n" "*" "$message" >/dev/tty
}
value1=$(
{
sleep 3
echo "Some data 1"
} &
spinwait $! "Loading data"
)
echo "Got value for task 1: $value1"
value2=$(
{
sleep 5
echo "Sone data 2"
} &
spinwait $!
)
echo "Got value for task 2: $value2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment