Skip to content

Instantly share code, notes, and snippets.

@zoolu-got-rhythm
Last active October 28, 2020 02:29
Show Gist options
  • Save zoolu-got-rhythm/6b2a968916c00982ee81a486c73683e5 to your computer and use it in GitHub Desktop.
Save zoolu-got-rhythm/6b2a968916c00982ee81a486c73683e5 to your computer and use it in GitHub Desktop.
a fancy loading animation using some shell scripting logic
# copy and paste the function into a bash and load into memory
# type: loadingAnimation
# function that increments and decrements forever
loadingAnimation()
{
#local variables? / state
duration=0
c=0
toggle=true
s=""
while [ true ]
do
clear
if [ "$toggle" = true ]
then
((c++))
s+="."
if [ "$c" -gt 50 ]
then
#switching
toggle=false
fi
else
c=$((c-1))
s=${s: : -1}
if [ "$c" -lt 1 ]
then
#switching
toggle=true
fi
fi
((duration++))
if [ "$duration" -eq 400 ]
then
# exit status 0
return
fi
echo "loading"
echo "$s"
sleep 0.03
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment