Slash animation in bash
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Slash animation in bash
Hi! I have one question, how to make a slash animation in bash? That is, there was a position \, then -,/, - and so on. Thank you in advance!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Slash animation in bash
I have this function in one of my scripts to show a spinner. You call the it with a bash statement as argument. When the bash statement returns false it stops the spinner. So it shows an animated spinner while waiting for some condition. If stdout isn't connected to a terminal it correctly doesn't output anything.
For example given $pid is the PID of a process started in the background, the following code would show the animated spinner until the background process has exited:
Code: Select all
spinner() {
local condition="$1"
if [[ -t 1 ]]; then
local frame=1
local frames='-\|/'
echo -n ' '
until eval "$condition"; do
echo -n $'\b'"${frames:frame++%${#frames}:1}"
sleep .1
done
echo -n $'\b'
else
while eval "$condition"; do
sleep .1
done
fi
}
Code: Select all
spinner "! kill -0 $pid &>/dev/null"
Re: Slash animation in bash
My AutoExec program has such a spinner, too. It starts at line 224, but there's a bit more going on; you should be able to get an idea as to how it works though.
Awesome spinner usage! Very cool stuff.
I'm also Terminalforlife on GitHub.