Created
October 24, 2016 06:14
-
-
Save hacker65536/9ebaccb4d9fc7238a948273710fbd39c to your computer and use it in GitHub Desktop.
trap spinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tmpdir=$(mktemp -d -p "./") | |
tmpf=$(mktemp -u) | |
mkfifo $tmpf | |
function progress(){ | |
#disappear cursor | |
echo -ne '\E[?25l' | |
local _spiner=("/" "-" "\\" "|") | |
#local _spiner=("+" "x") | |
local _i=0 | |
local _j=0 | |
#save cursor position | |
tput sc | |
#check pid exists | |
while [ -x /proc/"$1" ] | |
#while : | |
do | |
echo -en " $1 waiting for response.. \033[35m[${_spiner[$_i]}]\033[0m" | |
_i=$((_i + 1)) | |
_j=$((_j + 1)) | |
if [ $_i = 4 ]; then | |
_i=0 | |
fi | |
#restore cursor | |
tput rc | |
usleep 25000 | |
done | |
#erase line | |
tput el | |
#echo -en "\033[33m[respond]\033[0m\n" | |
#appear cursor | |
echo -en "\E[?25h" | |
} | |
function abc(){ | |
sleep 2 | |
echo "aa" > $tmpf & | |
} | |
(abc)& | |
pid=$! | |
echo $pid | |
progress $pid | |
ABC=$(cat $tmpf) | |
echo $ABC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment