#!/bin/sh # ttym on_start -- runs when a session begins. # # $1 mode countdown | stopwatch # $2 seconds requested duration of a countdown, 0 for a stopwatch # $3 comment the -c text, or an empty string # # Each hook works on its own: install only the ones you want. A hook that # is missing or not executable is skipped silently. # # timer waits for this to exit, so keep it quick. stdout and stderr go to # /dev/null -- printing here goes nowhere and cannot corrupt the progress # line. To debug, run the hook by hand: # # ~/.config/ttym/hooks/on_start countdown 1500 "+work" mode=$1 seconds=$2 comment=$3 # --- session record ------------------------------------------------------ # The log behind `timer -r` stores elapsed seconds only. It cannot tell a # finished 25m from an abandoned 30m that ran 25m, because the duration # you *asked for* is visible here and nowhere else. Pair this with the # matching lines in on_done and on_quit to get intent versus outcome. state=${XDG_STATE_HOME:-$HOME/.local/state}/ttym if mkdir -p "$state" 2>/dev/null; then printf '%s\tSTART\t%s\t%s\t%s\n' \ "$(date +%Y-%m-%dT%H:%M:%S)" "$mode" "$seconds" "$comment" \ >> "$state/sessions.tsv" fi # --- focus mode ---------------------------------------------------------- # Countdowns only: a stopwatch has no end, and silencing notifications # indefinitely is not what you want. If the process is killed with -9 # nothing restores these; recover with `dunstctl set-paused false`. if [ "$mode" = countdown ]; then command -v dunstctl > /dev/null 2>&1 && dunstctl set-paused true command -v playerctl > /dev/null 2>&1 && playerctl pause 2>/dev/null command -v mpc > /dev/null 2>&1 && mpc -q pause 2>/dev/null fi # --- timewarrior --------------------------------------------------------- # Turns -c comments into timew tags, so `timew summary :week +work` covers # timer sessions alongside everything else you track. Uncomment to use. # command -v timew > /dev/null 2>&1 && timew start ${comment:-timer} > /dev/null 2>&1 exit 0