Bash

Spinner During Long Task

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Show a rotating spinner next to a status message while a background command runs. Cosmetic but vastly improves the user experience of long scripts.
Bash
Raw
spinner() {
    local pid="$1" msg="$2"
    local chars="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
    local i=0
    while kill -0 "$pid" 2>/dev/null; do
        printf "\r%s %s " "${chars:i++%${#chars}:1}" "$msg"
        sleep 0.1
    done
    printf "\r✓ %s\n" "$msg"
}

with_spinner() {
    local msg="$1"; shift
    "$@" &
    spinner $! "$msg"
    wait $!
}

with_spinner "Downloading…" sleep 3
with_spinner "Installing…" sleep 2
with_spinner "Running tests" pytest -q
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.