-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimescreen
More file actions
executable file
·320 lines (274 loc) · 8.82 KB
/
timescreen
File metadata and controls
executable file
·320 lines (274 loc) · 8.82 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/zsh
#
# Note: up to 4.4, script began with doco details of TODO/BUGS/VersionLog
# Versionlog was then moved into it's own readme, and then into the commitlog
# of the timetools repo
### TODO's
# - some sanity checking on options - and existance of figlet and fonts...
# - controllable alarm clock
# - stopwatch/timer
# - able to run something external for chiming the hours (eg, `saytime` or `george`)
# - use tput rather than echo
# - set path to figlet as a variable
#
### BUGS
# - figfonts specified in rcfile may be overridden by the big fonts if the width is too wide...
#
# some default settings
DOLOOP=no
DOBEEP=no
DOFORTUNE=no
DOSECONDS=no
TALLSECONDS=no
FORTCOUNT=6
FIGBIN=/usr/bin/figlet
FIGDIR=/usr/share/figlet
LOLCAT=/usr/games/lolcat
# Default fonts - fit nicely in a 80 width screen.
# these may be overridden later by larger fonts if the $WIDTH is sufficient
# or by commandline settings. (highest priority)
# note: rcfile font options have same priority as here - $WIDTH will override!
DATEFONT=thick
TIMEFONT=colossal
# personal changes to defaults (above) can be baked into a config file:
RCFILE=$HOME/.timescreenrc
# let's parse these commandline arguments. all arguments should be - or --
# in nature, EXCEPT one. the width. why? cos I can code it this way at the
# moment ;)
# but also cos all other arguments at the moment are switches/toggles.
# there is nothing to set. The defaults are off, these switch them on. Sorry,
# but at the moment, that's how it is. I can't be bothered setting it up better
# ...besides, the default is the simplest. Cope.
tputsc=$(tput sc) # save cursor
tputel=$(tput el) # clear line
# restore cursor visibility on ^c exit
trap ctrl_c INT
function ctrl_c() {
echo ""
tput cnorm
tput cup $(tput lines) 0
exit 0
}
version="\
timescreen, by Owen Cameron <nemo@net.house.cx>
version 4 (rc file)
"
usage="\
Usage: timescreen [options] [--version] [--help]
options are
-w=xx (set width in chars)
-l (turn on looping)
-s (turn on second counter - only works when looping)
-d (double-height second counter)
-b (turn on chimes)
-f (turn on fortunes) (every 7 minutes)
-fn1=xxxx (figlet font for date)
-fn2=xxxx (figlet font for time)
-figbin=/path/to/figlet (full command path to figlet)
-rc=/path/to/.timescreenrc ($HOME/.timescreenrc by default)
** Note on fonts: by default, the date is displayed using figlet font 'thick'
** and the time using figlet font 'colossal'
** If -w is set, and the value is 95 or greater, then the default fonts become
** 'roman' for the date, and 'doh' for the time.
** The -fn1 and -fn2 settings have priority over both of these.
** 'showfigfonts(6)' if installed will give you a runthrough of all your fonts
"
for arg
do
opt=`echo $arg|sed 's/^\([^=]*\).*/\1/'`
val=`echo $arg|sed 's/^[^=]*=\(.*\)/\1/'`
case "$opt" in
-w) WIDTH="$val" ;;
-l) DOLOOP="yes" ; CLEARSCREEN="yes" ;; # CLEARSCREEN affects only start.
-b) DOBEEP="yes" ;;
-f) DOFORTUNE="yes" ;;
-s) DOSECONDS="yes" ;;
-d) TALLSECONDS="yes" ;;
-fn1) DATEFONT="$val" ; DATEFONT_FN1="yes" ;;
-fn2) TIMEFONT="$val" ; TIMEFONT_FN2="yes" ;;
-figbin) FIGBIN="$val" ;;
-rc) RCFILE="$val" ;;
--version) echo "$version"; exit 0 ;;
--help) echo "$version" "$usage"; exit 0 ;;
*) echo "timescreen: invalid option $arg
$usage" >&2
exit 1
;;
esac
done
# cursor invisible
tput civis
## check for the existance of a config file, and if it exists, use it.
if [ -x $RCFILE ]; then
. $RCFILE
fi
# determine $width. (if not set from -w). Use $COLUMNS from shell,
# then fall back to 80
if [ -z "$WIDTH" ]; then
if [ -z "$COLUMNS" ]; then
WIDTH=80
else
WIDTH=$COLUMNS
fi
fi
# setup relevant figletfonts for a width greater/equal to 105
# ONLY if they have not been set from the commandline
if [ "$WIDTH" -ge "105" ]; then
if [ -z "$DATEFONT_FN1" ]; then
DATEFONT=roman
fi
if [ -z "$TIMEFONT_FN2" ]; then
TIMEFONT=doh
fi
fi
do_centered() {
export IFS=x
cat /dev/stdin | while read line ; do printf "%-$(( ($WIDTH-${#line})/2 -2 ))s %s\n" " " "$line" ; done
unset IFS
}
# this simply prepends every line with a "clear line" control code
do_refreshline() {
export IFS=x
cat /dev/stdin | while read line ; do echo "${tputel}${line}" ; done
unset IFS
}
groovybar () {
SEC_ELAPSED=$(date '+%-S')
SEC_REMAINING=$((60-$SEC_ELAPSED))
tstamp=$(sleepenh 0)
if [ "$DOSECONDS" = "yes" ]; then
if [ "$WIDTH" -ge "125" ] ; then
# Due to control chars in groovybar I can't use the do_centered kludge
# ...so this is the alternate kludge
SPACES=$((($WIDTH-125)/2))
tput el
tput cuf ${SPACES}
echo -ne "-[${tputsc} .. .. || .. .. == .. .. || .. .. ]-"
if [ "$TALLSECONDS" = "yes" ]; then
echo ""
tput el
tput cuf ${SPACES}
echo "-[ ^^ ^^ || ^^ ^^ == ^^ ^^ || ^^ ^^ ]-"
fi
else
tput el
tput cuf $(( (WIDTH-64)/2 ))
echo "-[${tputsc} . . | . . O . . | . . ]-"
if [ "$TALLSECONDS" = "yes" ]; then
tput el
tput cuf $(( (WIDTH-64)/2 ))
echo "-[ | O | ]-"
fi
fi
# anything below the groovybar, put it here now:
echo "${tputel}"
# sketches on a unicode groovybar
# echo "╓─▄───╥─────╖" | do_centered | do_refreshline
# echo "╙─▀───╨─────╜" | do_centered | do_refreshline
# trailing info. fortune, or some kind of log check, etc
#
if [ "$DOFORTUNE" = "yes" ] && [ $FORTCOUNT -ge 3 ]; then
# tput ed
/usr/games/fortune -s | do_centered | $LOLCAT -f | do_refreshline
FORTCOUNT=0
else
md-count | column -c $WIDTH | head -n 5 | ccze -A | do_refreshline
fi
tput ed # and clear any remaining cruft
tput rc # go back to the groovybar and draw in the seconds
# so now we tell the groovybar to catch up those seconds...
if [ "$TALLSECONDS" = "yes" ]; then
if [ "$WIDTH" -ge "125" ] ; then
for i in $(seq 1 "$SEC_ELAPSED") ; do
echo -n "##" ; tput cub 2 ; tput cud 1 ; echo -n "##" ; tput cuu 1
done
else
for i in $(seq 1 "$SEC_ELAPSED") ; do
echo -n "#" ; tput cub 1 ; tput cud 1 ; echo -n "#" ; tput cuu 1
done
fi
else
if [ "$WIDTH" -ge "125" ] ; then
for i in `seq 1 "$SEC_ELAPSED"` ; do
echo -ne "##"
done
else
for i in `seq 1 "$SEC_ELAPSED"` ; do
echo -ne "#"
done
fi
fi
# and now print each remaining second, in turn, as it needs to be
if [ "$TALLSECONDS" = "yes" ]; then
if [ "$WIDTH" -ge "125" ] ; then
for i in $(seq 1 "$SEC_REMAINING") ; do
tstamp=$(sleepenh $tstamp 1.0)
echo -n "##" ; tput cub 2 ; tput cud 1 ; echo -n "##" ; tput cuu 1
done
else
for i in $(seq 1 "$SEC_REMAINING") ; do
tstamp=$(sleepenh $tstamp 1.0)
echo -n "#" ; tput cub 1 ; tput cud 1 ; echo -n "#" ; tput cuu 1
done
fi
else
if [ "$WIDTH" -ge "125" ] ; then
for i in $(seq 1 "$SEC_REMAINING") ; do
tstamp=$(sleepenh $tstamp 1.0)
echo -ne "##"
done
else
for i in $(seq 1 "$SEC_REMAINING") ; do
tstamp=$(sleepenh $tstamp 1.0)
echo -ne "#"
done
fi
fi
else
sleep $SEC_REMAINING
fi
}
# loop continuous and give us output!
while true ; do
if [ "$DOLOOP" = "yes" ] ; then
tput cup 0 0 # cursor to topleft
fi
if [ "$CLEARSCREEN" = "yes" ] ; then
tput clear
CLEARSCREEN="no"
fi
echo "${tputel}"
# echo " columns: $COLUMNS, width: $WIDTH, tput cols: $(tput cols)"
uptime | do_centered | do_refreshline
echo "${tputel}"
# display the date and time! important stuff!!
$FIGBIN -d $FIGDIR -f $DATEFONT -w $WIDTH -W "$(date '+%a %-d %b')" | do_centered | $LOLCAT -f | do_refreshline
echo -en "\e[1m"
$FIGBIN -d $FIGDIR -f $TIMEFONT -w $WIDTH -W "$(date '+%H:%M')" | do_centered | $LOLCAT -f | do_refreshline
echo -en "\e[0m"
FORTCOUNT=$(($FORTCOUNT+1))
# if it's on the hour, beep a few times as appropriate
if [ $(date '+%M') -eq "00" ]; then
OCLOCK=`date '+%l'`
# sleep a moment here to allow the rendering of the time to catch up
# on slow terminals. elsewise we lose each distinctive beep.
# Originally 5 seconds. Making it 1 here in the 2020s
sleep 1
if [ "$DOBEEP" = "yes" ]; then
echo -n "${tputel}"
for a in $(seq 1 $OCLOCK) ; do
echo -en "$a|\a\a\a"
sleep 1
done
fi
echo "It's $OCLOCK O'Clock and all's well!"
echo "${tputel}"
# CLEARSCREEN="yes"
fi
if [ "$DOLOOP" = "no" ]; then
ctrl_c # this handles our cleanup
fi
groovybar
done
# this should never be reached
exit 1