I have a shell script that backs up my git repos that are all saved in one specific file. I wanted to add a cool "spinning load thingy" just for fun and that's pretty simple. The problem is I realized I could still enter inputs into the terminal while it was loading and even worse I could still enter commands. You can find the back-up script on my GitHub page here or this is most of the code below.
function runCommand() {
load &
local whilePID=$!
tar -czf ${zipFileToUpdate} ${directoryToBackUp} &
local backupPID=$!
wait $backupPID
kill $whilePID
echo -ne "done"
}
function load() {
while true; do
echo -ne "/\r"
sleep .1
echo -ne "-\r"
sleep .1
echo -ne "\ \r"
sleep .1
echo -ne "|\r"
sleep .1
done
}
stty -echo # stop input
tput civis # cursor invisible
runCommand # main func
tput cnorm # cursor norm
stty echo # resume input
I started with the problem of being able to continuously type while the loading loop was running, with stty -echo I got that to stop but once I turn on the inputs again they all show up. So if I press the up arrow and enter, it'll just wait until it's done, then show that the script is running again. If anyone has any knowledge of how to capture the input instead of hiding it that'd be great!
I'm also new to bash, so if you could explain any commands or arguments that belong to commands that'd also be awesome. Thanks in advance