diff options
Diffstat (limited to 'hooks/on_quit')
| -rwxr-xr-x | hooks/on_quit | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/hooks/on_quit b/hooks/on_quit new file mode 100755 index 0000000..44957e8 --- /dev/null +++ b/hooks/on_quit @@ -0,0 +1,28 @@ +#!/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 +# +# A countdown abandoned after two seconds reports 2, not the duration +# you asked for. That is what makes this useful for tracking follow- +# through rather than intent. + +mode=$1 seconds=$2 comment=$3 + +log=${XDG_STATE_HOME:-$HOME/.local/state}/ttym +mkdir -p "$log" 2>/dev/null || exit 0 + +printf '%s\t%s\t%s\t%s\n' \ + "$(date +%Y-%m-%dT%H:%M:%S)" "$mode" "$seconds" "$comment" \ + >> "$log/abandoned.tsv" + +# Restore the terminal title set by on_start. +case $TERM in +xterm*|rxvt*|tmux*|screen*|alacritty|foot*) + printf '\033]0;%s\007' "${SHELL##*/}" > /dev/tty + ;; +esac |
