+focus() {
+ /p/c/proc/focus/linux-amd64/focus &
+ watcharb5
+ kill %%
+}
+
+
+watcharb5() {
+ local char ret
+ killall arbtt-capture ||:
+ rm -f ~/.arbtt/capture.log
+ arbtt-capture --sample-rate=10 &
+ clear
+ while true; do
+ arb5
+ ret=0
+ # i first thought to sleep and capture ctrl-c, but it seems we can't
+ # capture control-c, unless maybe we implement the commands in a
+ # separate script or maybe add err-cleanup to err. Anyways, this
+ # method is superior because any single char exits.
+ read -rsN1 -t 5 char || ret=$?
+ if (( ret == 142 )) || [[ ! $char ]]; then
+ # debug
+ #e ret=$ret char=$char
+ :
+ else
+ killall arbtt-capture ||:
+ return 0
+ fi
+ clear
+ done
+
+}
+
+arb5() {
+ local i l sec
+ i=0
+ if [[ ! -e ~/.arbtt/capture.log ]]; then
+ sleep 5
+ fi
+ # https://stackoverflow.com/questions/56486272/how-to-concat-multiple-fields-to-same-line-with-jq
+ arbtt-dump -l 30 -t json | jq -r '.[] | [ ( .inactive / 1000 | floor ) , ( .windows[] | select (.active == true) |.title) ] | @tsv' \
+ | tac | while read -r sec l; do
+ if (( i % 6 == 0 && i >= 2 )); then
+ echo == $(( i / 6 + 1 )) ==
+ fi
+ if (( sec > 10 )); then
+ printf "%3d %s\n" $sec "$l"
+ else
+ printf " %s\n" "$l"
+ fi
+ i=$(( i + 1 ))
+ done
+}
+
+arbttlog() {
+ # from the log, show only the currently active window, and the number of
+ # seconds of input inactivity.
+ arbtt-dump "$@" | grep -v '( )\|Current Desktop' | sed -rn '/^[^ ]/{N;s/^(.{21})([0-9]*)[0-9]{3}m.*\(\*/\1\2/;s/^(.{21})[0-9]*.*\(\*/\1/;s/\n//;p}' ; }