Compare commits

...

4 Commits

2 changed files with 39 additions and 19 deletions

View File

@@ -1,20 +1,9 @@
# CountDown.sh
A simple script to countdown from a certain number to zero. I made it so that
I can easily delay the playing time of songs by a few seconds before I play it
on the guitar.
```
USAGE:
countdown.sh <sec>
OPTIONS:
<sec> number to countdown from [default: 5]
EXAMPLE:
Countdown from 7 and then play Scott Stapp's "Last Hallelujah"
./countdown 7 ; mpv 12_-_Last_Hallelujah.flac
```
## License
This project is licensed under the terms & conditions of the ZLib license.

View File

@@ -22,17 +22,48 @@
# 3. This notice may not be removed or altered from any source
# distribution.
if [ -z $1 ]
set -euo pipefail
INLINE=0
COUNT=5
if [ $# -ge 1 ] && [ $# -le 2 ]
then
COUNT=5
else
COUNT=$1
for arg in "$@"
do
if [ "$arg" = "-i" ]
then
INLINE=1
elif [ "$arg" = "-h" ] || [ "$arg" = "--help" ]
then
echo "Usage: $0 [-i] [COUNT]"
echo " COUNT: Number of seconds to count down from (default: 5)"
echo " -i: Inline mode (do not print each number on a new line)"
exit 0
elif [[ "$arg" =~ [0-9]+ ]]
then
COUNT="$arg"
else
echo "Unknown argument: $arg"
exit 1
fi
done
fi
for i in $(seq $COUNT -1 1)
for i in $(seq "$COUNT" -1 1)
do
echo $i
if [ $INLINE -eq 0 ]
then
echo "$i"
else
printf "\r%s" "$i"
fi
sleep 1
done
echo 0
if [ $INLINE -eq 0 ]
then
echo "0"
else
printf "\r%s\n" "0"
fi