mirror of
https://github.com/tiyn/dotfiles.git
synced 2025-04-19 16:27:45 +02:00
Compare commits
4 Commits
415f14234b
...
80de5641a3
Author | SHA1 | Date | |
---|---|---|---|
80de5641a3 | |||
e1a511b577 | |||
187e94dcbc | |||
4968399e4a |
52
.local/bin/tools/timer
Executable file
52
.local/bin/tools/timer
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
help="""
|
||||||
|
usage: timer [option] [args]
|
||||||
|
options:
|
||||||
|
-c SECONDS Count down from given amount of seconds
|
||||||
|
-s Start stopwatch
|
||||||
|
-h Display this message
|
||||||
|
"""
|
||||||
|
|
||||||
|
max_seconds=86400
|
||||||
|
|
||||||
|
countdown() {
|
||||||
|
start="$(( $(date '+%s') + $1))"
|
||||||
|
while [ $start -ge $(date +%s) ]; do
|
||||||
|
time="$(( $start - $(date +%s) ))"
|
||||||
|
if [ $time -ge $max_seconds ]; then
|
||||||
|
echo "Maximum number of seconds ($max_seconds) for countdown surpassed."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
stopwatch() {
|
||||||
|
start=$(date +%s)
|
||||||
|
while true; do
|
||||||
|
time="$(( $(date +%s) - $start))"
|
||||||
|
printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
|
||||||
|
if [ $time -ge $max_seconds ]; then
|
||||||
|
echo "Maximum number of seconds ($max_seconds) reached."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
no_args="true"
|
||||||
|
while getopts "c:sh" arg; do
|
||||||
|
case $arg in
|
||||||
|
c) countdown $OPTARG;;
|
||||||
|
s) stopwatch;;
|
||||||
|
h) echo "$help";;
|
||||||
|
*) echo "$help";;
|
||||||
|
esac
|
||||||
|
no_args="false"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$no_args" = "true" ]; then
|
||||||
|
echo "$help"
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user