Last active
November 29, 2019 13:51
-
-
Save Katalam/264041d1080d717e6feb3605134782b7 to your computer and use it in GitHub Desktop.
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 | |
clear # clears the terminal in the beginning | |
length=20 # time in seconds to wait before command is executed again | |
exitcode=0 # exit variable can be set to 1 to exit while loop | |
updateinterval=1 # update interval of the loading bar in seconds | |
# Exitcode could be set to 1 if while should end | |
while [ exitcode != 1 ] | |
do | |
# basic calculation for size of loading bar based on the time with the update interval | |
size=`echo "scale=0 ; $length / $updateinterval" | bc` | |
# clear the terminal | |
clear | |
# Header text | |
echo "Execute command every $length seconds" | |
# Add command here | |
# for example | |
svn up | |
# for loop for adding the chars for the loading bbar | |
for ((i = 0; i <= size; i++)) | |
do | |
# the output needs a closing bracket and a \r for using the same line everytime | |
output="]\r" | |
# first for loop for the empty area of the loading bar | |
for ((a = 0; a <= size-i; a++)) | |
do | |
# exisiting output will be put back into the output with a extra dot | |
output=".$output" | |
done | |
# second for loop for the marked area of the loading bar | |
for ((b = size; b >= size-i; b--)) | |
do | |
# exisiting output will be put back into the output with a extra hastag | |
output="█$output" | |
done | |
# existing output will be closed with a opening bracket | |
output="[$output" | |
# final echo of the output | |
# -ne for using the same line and do not use a linebreak after | |
echo -ne $output | |
# sleep in seconds for the timing of the loading bar | |
# Loading bar is based on the length and updateinterval defined above | |
# sleep only as long as the updateinterval | |
sleep $updateinterval | |
done | |
# for loop for the loading bar is done here and will be started again with the while | |
done | |
# while loop is done here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment