#!/bin/sh # ttym on_quit -- runs when a session ends early: q, Ctrl+C, SIGTERM, # SIGQUIT or SIGHUP -- and whenever a stopwatch is stopped, since a # stopwatch has no natural end. # # $1 mode countdown | stopwatch # $2 seconds time actually elapsed, excluding time spent paused # $3 comment the -c text, or an empty string # # $2 is what really ran, not what you asked for: a 25m countdown # abandoned after four minutes reports 240. Compare against the START # line written by on_start to see follow-through. # # If your build has the logging patch, `timer -r` already records this # session -- it logs every run, completed or not. What it cannot show is # that the run was cut short, which is what the record below adds. mode=$1 seconds=$2 comment=$3 # --- session record ------------------------------------------------------ state=${XDG_STATE_HOME:-$HOME/.local/state}/ttym if mkdir -p "$state" 2>/dev/null; then printf '%s\tQUIT\t%s\t%s\t%s\n' \ "$(date +%Y-%m-%dT%H:%M:%S)" "$mode" "$seconds" "$comment" \ >> "$state/sessions.tsv" fi # --- leave focus mode ---------------------------------------------------- command -v dunstctl > /dev/null 2>&1 && dunstctl set-paused false [ "$mode" = countdown ] && command -v playerctl > /dev/null 2>&1 && playerctl play 2>/dev/null [ "$mode" = countdown ] && command -v mpc > /dev/null 2>&1 && mpc -q play 2>/dev/null # --- timewarrior --------------------------------------------------------- # command -v timew > /dev/null 2>&1 && timew stop > /dev/null 2>&1 exit 0