Upgrade yt-dlp from version `stable@2024.05.27` to `stable@2024.07.09`
[sunny256-utils.git] / til-ov
blob099063b450944a7fcd4dc2b7e7ea2dbcfb20929d
1 #!/usr/bin/env bash
3 #=======================================================================
4 # til-ov
5 # File ID: 75a10a58-8f7e-11e5-a744-fefdb24f8e10
7 # [Description]
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=til-ov
14 VERSION=0.3.0
16 ARGS="$(getopt -o "\
22 " -l "\
23 help,\
24 init,\
25 quiet,\
26 reverse,\
27 verbose,\
28 version,\
29 " -n "$progname" -- "$@")"
30 test "$?" = "0" || exit 1
31 eval set -- "$ARGS"
33 opt_help=0
34 opt_init=0
35 opt_quiet=0
36 opt_reverse=0
37 opt_verbose=0
38 while :; do
39 case "$1" in
40 -h|--help) opt_help=1; shift ;;
41 -i|--init) opt_init=1; shift ;;
42 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
43 -r|--reverse) opt_reverse=1; shift ;;
44 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
45 --version) echo $progname $VERSION; exit 0 ;;
46 --) shift; break ;;
47 *) echo $progname: Internal error >&2; exit 1 ;;
48 esac
49 done
50 opt_verbose=$(($opt_verbose - $opt_quiet))
52 if test "$opt_help" = "1"; then
53 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
54 cat <<END
56 Usage: $progname [options] [km [timestamp]]
58 Options:
60 -h, --help
61 Show this help.
62 -i, --init
63 Init the spar db with initial values.
64 -q, --quiet
65 Be more quiet. Can be repeated to increase silence.
66 -r, --reverse
67 Count km in reverse order, from 0 and up.
68 -v, --verbose
69 Increase level of verbosity. Can be repeated.
70 --version
71 Print version information.
73 END
74 exit 0
77 destkm=$1
78 desttime=$2
80 test -z "$desttime" && desttime=18:00
81 test -z "$destkm" && destkm=7.68
83 currdate="$(date -u +%Y-%m-%d)"
84 currtime="$(date -u +%H:%M:%S)"
85 currsec=$(date -u +%s)
87 destdate="$currdate $desttime"
88 echo "$desttime" | grep -q ' ' && {
89 destdate="$desttime"
92 if test "$opt_init" = "1"; then
93 if test "$opt_reverse" = "1"; then
94 beginkm=0
95 endkm=$destkm
96 else
97 beginkm=$destkm
98 endkm=0
100 spar ov \
101 --bt "$currdate $currtime" \
102 --et "$destdate" \
103 --bv "$beginkm" \
104 --ev "$endkm" \
105 >/dev/null
108 destsec=$(date -u -d "$destdate" +%s)
109 printf '%.2f km/h\n' $(echo "$destkm/($destsec-$currsec)*3600" | bc)
111 while :; do
112 printf '%.3f\n' $(spar ov)
113 sleep 1
114 done | uniq