Compare commits
2 Commits
4240b99f84
...
c9d04788a7
| Author | SHA1 | Date | |
|---|---|---|---|
| c9d04788a7 | |||
| 044850c200 |
13
README.md
13
README.md
@@ -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.
|
||||
|
||||
53
countdown.sh
53
countdown.sh
@@ -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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user