forked from anishathalye/dotfiles_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minutes-left
executable file
·115 lines (88 loc) · 2.18 KB
/
minutes-left
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# damato 2014
PROGNAME=${0##*/}
PROGVERSION=0.1
declare VOLUME=100 # volume of speech 0-100
declare LOOP=0 # number of times to repeat end message, 0=forever
declare ALARM="Time is up" # alarm message
declare DEBUG=
declare LEFT # time until next warning
usage()
{
cat << EO
minutes-left [-m] minutes [options]
EO
cat <<EO | column -s\& -t
-h, --help & show this output
-m, --minutes & minutes to count down
-v, --volume & audio volume (0-100)
-r, --repeat & how many times to repeat final alarm (0=forever)
-a, --alarm-message & text to be spoken at the end of the countdown
-d, --debug & skip delays during countdown
EO
}
SHORTOPTS="hdm:v:r:a:"
LONGOPTS="help,minutes:,volume:,repeat:,alarm-message:,debug"
ARGS=$(getopt -s bash --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGNAME -- "$@")
eval set -- "$ARGS"
while true; do
case $1 in
-h|--help)
usage; exit 0;;
-v|--volume)
VOLUME=$2; shift;;
-r|--repeat)
LOOP=$2; shift;;
-a|--alarm-message)
ALARM="$2"; shift;;
-d|--debug)
DEBUG="true";;
-m|--minutes)
LEFT=$2; shift;;
--)
break;;
# LEFT=$2; break;;
esac
shift
done
function dump_if_debug () {
[ $DEBUG ] && cat <<EOF | column -s\& -t
VOLUME & $VOLUME
LOOP & $LOOP
ALARM & $ALARM
MINUTES & $LEFT
DEBUG & $DEBUG
EOF
}
dump_if_debug
(( LEFT > 0 )) || { usage; exit 1; }
#(( $1 )) || { echo "usage: minutes-left MINUTES [ VOLUME [ LOOP [ SKIP-SLEEP ]]]"; exit; }
set -e
declare MSG
declare SLEEP
function repeat () {
gtts-cli -o /tmp/say.mp3 "${@:2}"
mplayer -volume $VOLUME -loop $1 \
-quiet -nolirc /tmp/say.mp3
> /dev/null; # only show stderr from mplayer
}
function _repeat () {
espeak "${@:2}"
}
function say () { repeat 1 "$*"; }
while (( LEFT > 0 )); do
MSG="$LEFT minute"
(( LEFT > 1 )) && MSG="${MSG}s"
MSG="${MSG} left until $ALARM"
echo $MSG
say "$MSG" > /dev/null
SLEEP=$(( $LEFT ))
LEFT=$(( 2 * LEFT / 3))
echo "Next warning at $LEFT minutes left"
SLEEP=$(( SLEEP - LEFT ))
echo "Sleeping for $SLEEP minutes"
sleep $(( SLEEP * 60 ))
done
while (( 1 )); do
repeat $LOOP "$ALARM" > /dev/null
done