-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.sh
executable file
·32 lines (30 loc) · 887 Bytes
/
sw.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# Found these while looking for crap online and wanted to recod them for posterity
countdown(){
date1=$((`date +%s` + $1));
while [ "$date1" -ge `date +%s` ]; do
## Is this more than 24h away?
days=$(($(($(( $date1 - $(date +%s))) * 1 ))/86400))
echo -ne "$days day(s) and $(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S)\r";
sleep 0.1
done
}
stopwatch(){
date1=`date +%s`;
while true; do
days=$(( $(($(date +%s) - date1)) / 86400 ))
echo -ne "$days day(s) and $(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r";
sleep 0.1
done
}
if [[ $1 == "countdown" ]];then
countdown $2
elif [[ $1 == "stopwatch" ]];then
stopwatch
else
printf "\nUsage is ./sw.sh (type) where type is:\n"
printf "\tcountdown - to run a countdown timer\n"
printf "\tstopwatch - to start a stopwatch\n"
printf "\n"
exit
fi