#!/usr/bin/env bash # Source: https://github.com/Silejonu/bash_loading_animations # shellcheck disable=SC2034 # https://github.com/koalaman/shellcheck/wiki/SC2034 ### Loading animations list ### # The first value of an array is the interval (in seconds) between each frame ## ASCII animations ## # Will work in any terminal, including the TTY. BLA_classic=( 0.25 '-' "\\" '|' '/' ) BLA_box=( 0.2 ┤ ┴ ├ ┬ ) BLA_bubble=( 0.6 · o O O o · ) BLA_breathe=( 0.9 '  ()  ' ' (  ) ' '(    )' ' (  ) ' ) BLA_growing_dots=( 0.5 '.  ' '.. ' '...' '.. ' '.  ' '   ' ) BLA_passing_dots=( 0.25 '.  ' '.. ' '...' ' ..' '  .' '   ' ) BLA_metro=( 0.2 '[    ]' '[=   ]' '[==  ]' '[=== ]' '[ ===]' '[  ==]' '[   =]' ) BLA_snake=( 0.4 '[=     ]' '[~<    ]' '[~~=   ]' '[~~~<  ]' '[ ~~~= ]' '[  ~~~<]' '[   ~~~]' '[    ~~]' '[     ~]' '[      ]' ) BLA_filling_bar=( 0.25 '█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '█████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '██████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '███████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '█████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '█████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '██████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '███████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '█████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '██████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒' '███████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒' '████████████████████▒▒▒▒▒▒▒▒▒▒▒▒' '█████████████████████▒▒▒▒▒▒▒▒▒▒▒' '██████████████████████▒▒▒▒▒▒▒▒▒▒' '███████████████████████▒▒▒▒▒▒▒▒▒' '████████████████████████▒▒▒▒▒▒▒▒' '█████████████████████████▒▒▒▒▒▒▒' '██████████████████████████▒▒▒▒▒▒' '███████████████████████████▒▒▒▒▒' '████████████████████████████▒▒▒▒' '█████████████████████████████▒▒▒' '██████████████████████████████▒▒' '███████████████████████████████▒' '████████████████████████████████') ## UTF-8 animations ## # Require Unicode support (will work in most modern terminals, but not in TTY). # Some animations may not render properly with certain fonts. BLA_classic_utf8=( 0.25 '—' "\\" '|' '/' ) BLA_bounce=( 0.3 . · ˙ · ) BLA_vertical_block=( 0.25 ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁ ) BLA_horizontal_block=( 0.25 ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▉ ▊ ▋ ▌ ▍ ▎ ▏ ) BLA_quarter=( 0.25 ▖ ▘ ▝ ▗ ) BLA_triangle=( 0.45 ◢ ◣ ◤ ◥) BLA_semi_circle=( 0.1 ◐ ◓ ◑ ◒ ) BLA_rotating_eyes=( 0.4 ◡◡ ⊙⊙ ⊙⊙ ◠◠ ) BLA_firework=( 0.4 '⢀' '⠠' '⠐' '⠈' '*' '*' ' ' ) BLA_braille=( 0.2 ⠁ ⠂ ⠄ ⡀ ⢀ ⠠ ⠐ ⠈ ) BLA_braille_whitespace=( 0.2 ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷ ) BLA_trigram=( 0.25 ☰ ☱ ☳ ☶ ☴ ) BLA_arrow=( 0.15 ▹▹▹▹▹ ▸▹▹▹▹ ▹▸▹▹▹ ▹▹▸▹▹ ▹▹▹▸▹ ▹▹▹▹▸ ▹▹▹▹▹ ▹▹▹▹▹ ▹▹▹▹▹ ▹▹▹▹▹ ▹▹▹▹▹ ▹▹▹▹▹ ▹▹▹▹▹ ) BLA_bouncing_ball=( 0.4 '(●     )' '( ●    )' '(  ●   )' '(   ●  )' '(    ● )' '(     ●)' '(    ● )' '(   ●  )' '(  ●   )' '( ●    )' ) BLA_big_dot=( 0.7 ∙∙∙ ●∙∙ ∙●∙ ∙∙● ) BLA_modern_metro=( 0.15 ▰▱▱▱▱▱▱ ▰▰▱▱▱▱▱ ▰▰▰▱▱▱▱ ▱▰▰▰▱▱▱ ▱▱▰▰▰▱▱ ▱▱▱▰▰▰▱ ▱▱▱▱▰▰▰ ▱▱▱▱▱▰▰ ▱▱▱▱▱▱▰ ▱▱▱▱▱▱▱ ▱▱▱▱▱▱▱ ▱▱▱▱▱▱▱ ▱▱▱▱▱▱▱ ) BLA_pong=( 0.35 '▐⠂       ▌' '▐⠈       ▌' '▐ ⠂      ▌' '▐ ⠠      ▌' '▐  ⡀     ▌' '▐  ⠠     ▌' '▐   ⠂    ▌' '▐   ⠈    ▌' '▐    ⠂   ▌' '▐    ⠠   ▌' '▐     ⡀  ▌' '▐     ⠠  ▌' '▐      ⠂ ▌' '▐      ⠈ ▌' '▐       ⠂▌' '▐       ⠠▌' '▐       ⡀▌' '▐      ⠠ ▌' '▐      ⠂ ▌' '▐     ⠈  ▌' '▐     ⠂  ▌' '▐    ⠠   ▌' '▐    ⡀   ▌' '▐   ⠠    ▌' '▐   ⠂    ▌' '▐  ⠈     ▌' '▐  ⠂     ▌' '▐ ⠠      ▌' '▐ ⡀      ▌' '▐⠠       ▌' ) BLA_earth=( 0.45 🌍 🌎 🌏 ) BLA_clock=( 0.2 🕛 🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 ) BLA_moon=( 0.8 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 ) BLA_orange_pulse=( 0.35 🔸 🔶 🟠 🟠 🔶 ) BLA_blue_pulse=( 0.35 🔹 🔷 🔵 🔵 🔷 ) BLA_football=( 0.25 ' 👧⚽️       👦' '👧  ⚽️      👦' '👧   ⚽️     👦' '👧    ⚽️    👦' '👧     ⚽️   👦' '👧      ⚽️  👦' '👧       ⚽️👦 ' '👧      ⚽️  👦' '👧     ⚽️   👦' '👧    ⚽️    👦' '👧   ⚽️     👦' '👧  ⚽️      👦' ) BLA_blink=( 0.25 😐 😐 😐 😐 😐 😐 😐 😐 😐 😑 ) BLA_camera=( 0.1 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📷 📸 📷 📸 ) BLA_sparkling_camera=( 0.1 '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📷 ' '📸✨' '📷 ' '📸✨' ) BLA_sick=( 0.9 🤢 🤢 🤮 ) BLA_monkey=( 0.4 🙉 🙈 🙊 🙈 ) BLA_bomb=( 0.25 '💣   ' ' 💣  ' '  💣 ' '   💣' '   💣' '   💣' '   💣' '   💣' '   💥' '    ' '    ' ) declare -a BLA_active_loading_animation BLA::play_loading_animation_loop() { while true ; do for frame in "${BLA_active_loading_animation[@]}" ; do printf "\r%s" "${frame}" sleep "${BLA_loading_animation_frame_interval}" done done } BLA::start_loading_animation() { BLA_active_loading_animation=( "${@}" ) # Extract the delay between each frame from array BLA_active_loading_animation BLA_loading_animation_frame_interval="${BLA_active_loading_animation[0]}" unset "BLA_active_loading_animation[0]" tput civis # Hide the terminal cursor BLA::play_loading_animation_loop & BLA_loading_animation_pid="${!}" } BLA::stop_loading_animation() { kill "${BLA_loading_animation_pid}" &> /dev/null printf "\n" tput cnorm # Restore the terminal cursor } ############################################################################### ################################# USAGE GUIDE ################################# ############################################################################### ################## Read below for the explanations on how to ################## ################### show loading animations in your script. ################### ############################################################################### :<<'EXAMPLES' ## Put these lines at the top of your script: ## (replace /path/to/bash_loading_animations.sh with the appropriate filepath) # Load in the functions and animations source /path/to/bash_loading_animations.sh # Run BLA::stop_loading_animation if the script is interrupted trap BLA::stop_loading_animation SIGINT # Show a loading animation for the command "foo" BLA::start_loading_animation "${BLA_name_of_the_animation[@]}" foo BLA::stop_loading_animation # If foo prints some output in the terminal, you may want to add: foo 1> /dev/null # hide standard output # or foo 2> /dev/null # hide error messages # or foo &> /dev/null # hide all output EXAMPLES