blob: 21c64f910c1846271d0930a578390a5828e08b9c (
plain)
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
|
#!/bin/sh
# utility variables and functions
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" # XDG basedir specification
# this variable grows automatically as long as this file is included in each
# subcommand
export subcmd="$subcmd${subcmd:+ }$(basename "$0")"
# print an error to stdout and exit
err() {
echo "error: $*" >&2
echo "run \`$subcmd --help\` for options" >&2
exit 1
}
# debug:
# bc() { tee /dev/stderr | /usr/bin/bc ; }
fmt_time() {
ss="$(echo "$1 / 1" | bc)"
mm="$(echo "$ss / 60" | bc)"
ss="$(echo "$ss % 60" | bc)"
hh="$(echo "$mm / 60" | bc)"
mm="$(echo "$mm % 60" | bc)"
_time_fmt
}
_time_fmt() { # [HH:]MM:SS
[ $hh -gt 0 ] && printf '%02d:' $hh
printf "%02d:%02d\n" $mm $ss
}
# _time_fmt() { # [HHh]MMmSSs
# [ $hh -gt 0 ] && printf '%02dh' $hh
# printf "%02dm%02ds\n" $mm $ss
# }
|