2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
5 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
7 source /a
/bin
/errhandle
/err
13 for p
in ~
/.gem
/ruby
/*/bin
; do
17 todaycache
=/tmp
/timetraptoday
19 if [[ ! -e $todaycache ]]; then
22 ! find $todaycache -mmin $1 -type f
-exec false
{} + &>/dev
/null
24 td
() { /a
/opt
/timetrap
/bin
/t d
-ftotal all
-m '^w|x$' "$@"; }
29 if [[ -e /dev
/shm
/iank-status
]]; then
30 eval $
(< /dev
/shm
/iank-status
)
34 cursheet
=$
(sqlite3
/p
/.timetrap.db
"select sheet from entries where end is NULL;")
36 if [[ $cursheet ]]; then
37 if i3-msg
-t get_bar_config bar-0 |
grep '"mode":"dock"' &>/dev
/null
; then
38 i3-msg
-q 'bar mode hide'
41 if i3-msg
-t get_bar_config bar-0 |
grep '"mode":"hide"' &>/dev
/null
; then
42 i3-msg
-q 'bar mode dock'
47 # maybe sometime show work and x separate
49 today
=$
(< /tmp
/timetraptoday
)
51 today
=$
(< /tmp
/timetraptoday
)
52 td
-s today
>/tmp
/timetraptoday
&
55 echo "$today" >/tmp
/timetraptoday
58 # hours remaining in the day:
60 # work+study in the last week, not counting today.
61 # no arg to printf for the intentional behavior of no arg
62 # shellcheck disable=SC2183
63 cache
=/tmp
/timetrap$
(printf '%(%F)T')
64 if [[ -e $cache ]]; then
67 week
=$
(td
-s '8 days ago' -e 'yesterday')
68 printf 'week="%s"\n' "$week" >$cache
69 week4
=$
(td
-s '29 days ago' -e 'yesterday')
70 printf 'week4="%s"\n' "$week4" >>$cache
72 # weekly work+study in the last 4 weeks, not counting today.
75 # ($x4week + $w4week + .05) /4
76 #weekly work+study in the last 16 weeks, not counting today.
77 #weekly work+study in the last 52 weeks, not counting today.
79 unixtime
=$EPOCHSECONDS
80 midnight
=$
(date +%s
-d 'tomorrow 00:00')
81 tmp
=($
(echo "scale=1; today_left=($midnight-$unixtime) / 60 / 60;
83 done_today=($today + .05) /1;
84 /* hours I could do today by working 80% of the remainder time */
85 today_left * .8 + done_today;
88 ($week4 + .05) /4"|
bc))
89 printf "[ { \"full_text\": \""
90 if [[ $ps_char ]]; then
91 printf "%s| " "$ps_char"
93 printf "%s | left today %s %s | today %s | week %s | 4weeks %s | %s\" } ],\n" "$cursheet" "${tmp[@]}" "$(date "+%A
, %B
%d
, %r
")"
96 # pass any arg and we just run once
100 printf '{ "version": 1 }\n['