mirror of
https://github.com/endeavouros-team/eos-bash-shared.git
synced 2026-06-13 01:34:36 +00:00
47 lines
1014 B
Bash
Executable File
47 lines
1014 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Show a waiting indicator on the terminal.
|
|
# Usage: eos-waiting-indicator lock-file
|
|
|
|
DIE() {
|
|
echo "Error: $1" >&2
|
|
exit 1
|
|
}
|
|
|
|
ShowIndicator() {
|
|
local str items
|
|
# items=( "◡◡" "⊙⊙" "◠◠" )
|
|
# items=( "◴" "◷" "◶" "◵" )
|
|
# items=( "▁" "▂" "▃" "▄" "▅" "▆" "▇" "█" "▇" "▆" "▅" "▄" "▃" "▁" )
|
|
items=( "◢" "◣" "◤" "◥" )
|
|
|
|
tput civis # hide cursor
|
|
#printf "%s\n" "$prompt" >&2
|
|
case "$1" in
|
|
-nl) printf "\n" >&2 ;;
|
|
esac
|
|
while true ; do
|
|
for str in "${items[@]}" ; do
|
|
printf "\r%s %s" "$prompt" "$str" >&2
|
|
if [ ! -r "$lockfile" ] ; then
|
|
tput cnorm # unhide cursor
|
|
return
|
|
fi
|
|
sleep 0.25
|
|
done
|
|
done
|
|
}
|
|
|
|
Main()
|
|
{
|
|
local lockfile="$1"
|
|
local prompt="$2"
|
|
|
|
[ -n "$lockfile" ] || DIE "lockfile argument missing"
|
|
[ -r "$lockfile" ] || DIE "lockfile does not exist"
|
|
|
|
ShowIndicator -nl
|
|
}
|
|
|
|
Main "$@"
|