-
Notifications
You must be signed in to change notification settings - Fork 2
/
stopwatch
executable file
·62 lines (54 loc) · 1.11 KB
/
stopwatch
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/stopwatch
#
PROG="${0##*/}"
trap cleanup SIGINT SIGTERM SIGKILL SIGQUIT SIGABRT SIGSTOP SIGSEGV
cleanup() {
echo -e "\n\n"
exit 0
}
usage() {
echo "${PROG} [-cC]"
echo " -c clears the screen"
echo " -C pipe the output to CowSay"
exit 1
}
while getopts ':cC' opt; do
case $opt in
c) CLEAR=1 ;
;;
C) COW=1;
;;
*) echo "Invalid option: -$OPTARG";
usage;
;;
esac
done
[[ 1 -eq ${CLEAR:-0} ]] && clear
while [ 1 ]
do
if [ 0 -eq ${COW:-0} ]
then
printf "\rTime(HH:MM:SS) - %02d:%02d:%02d" ${HOURS:-0} ${MINS:-0} ${SECS:-0}
else
clear
printf "Time(HH:MM:SS) - %02d:%02d:%02d" ${HOURS:-0} ${MINS:-0} ${SECS:-0} | cowsay
fi
if [ ${SECS:-0} -ge 59 ]
then
SECS=0
if [ ${MINS:-0} -ge 59 ]
then
MINS=0
HOURS=$(( $HOURS + 1 ))
else
MINS=$(( $MINS + 1 ))
fi
else
SECS=$(( SECS + 1 ))
fi
sleep 1
done