Skip to content

Instantly share code, notes, and snippets.

@dideler
Last active October 1, 2023 16:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dideler/b0a0ef8b95e683752883 to your computer and use it in GitHub Desktop.
Save dideler/b0a0ef8b95e683752883 to your computer and use it in GitHub Desktop.
Basic CLI loading animation
#!/usr/bin/env bash
for i in {0..12}; do
if ! (($i % 4)); then
printf "\e[1K\rloading"
else
printf "."
fi
sleep 1
done && printf "\e[2K\r"
@dideler
Copy link
Author

dideler commented Nov 18, 2015

The terminal escapes are the interesting part.

\033[1K or \e[1K will clear from the cursor position to the beginning of the line.
\033[2K or \e[2K will clear everything on the line.

@mateusza
Copy link

mateusza commented Oct 1, 2023

you don't put $i in (( )). Just i is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment