Skip to content

Instantly share code, notes, and snippets.

@gpoulter
Last active May 2, 2023 10:45
Show Gist options
  • Save gpoulter/deb958233f264c08964b0151802faf39 to your computer and use it in GitHub Desktop.
Save gpoulter/deb958233f264c08964b0151802faf39 to your computer and use it in GitHub Desktop.
Track time using timelapse.sh and winstats.sh scripts
#!/usr/bin/fish
#
# Tracks window titles and records a timelapse for specified duration.
#
# Duration for running the tracker - quits after sleeping this long.
set duration "25m"
# Name of project to record in the time entries.
set project "none"
# Parse flags.
argparse --name="track" "p/project=" "d/duration=" -- $argv or exit 1
set -q _flag_duration; and set duration $_flag_duration
set -q _flag_project; and set project $_flag_project
# Introduce the tracking
set title (printf "Tracking \"%s\" for %s starting at %s" $project $duration (date +%H:%M:%S))
echo $title
echo -ne "\033]0;$title\007"
# Start tracking window titles.
winstats.fish --project "$project" &
# Start tracking screen recording.
timelapse.fish --project "$project" &
function stopjobs --on-signal HUP
echo "Stopping winstats and timelapse."
# Kills the process group of the shell.
# Necessary to kill the sleep and ffmpeg subprocesses.
kill -- -$fish_pid
end
# Wait for the Pomodoro and exit everything
echo "Sleeping for $duration"
sleep $duration
notify-send "Finished tracking \"$project\""
stopjobs
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment