Compare commits

...

2 Commits

Author SHA1 Message Date
c9d04788a7 Allow inline countdown. 2026-03-02 15:55:53 +01:00
044850c200 Simplify README.md 2026-03-02 15:40:57 +01:00
2 changed files with 37 additions and 29 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

@@ -24,27 +24,46 @@
set -euo pipefail
if [ $# -gt 1 ]
then
echo "Too many arguments"
echo "Usage: $0 [COUNT]"
exit 1
elif [ $# -eq 1 ] && [ "$1" = "-h" ]
then
echo "Usage: $0 [COUNT]"
exit 0
elif [ $# -eq 1 ] && [ "$1" -le 0 ]
then
echo "COUNT must be a positive integer"
exit 1
fi
INLINE=0
COUNT=5
COUNT=${1:-5}
if [ $# -ge 1 ] && [ $# -le 2 ]
then
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)
do
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