Time Since Last Resume
It's handy to know when to take a break:
➜ ~ sinceresume.sh 0
14 minutes since your last break (Sep 13 13:56:49)
Supported OSes (patches welcome):
- Pantheon Desktop
- Ubuntu Desktop
Log the time when the system resumes from standby / sleep / hibernation
Reference: System-D Suspend Service
$ sudo nano /usr/lib/systemd/system-sleep/sinceresume
#!/bin/sh
case $1 in
post)
logger "sinceresume resumed"
;;
esac
Time since last resume
Going forward I maintain the fish version:
#!/usr/bin/env fish
set display_threshold (count $argv > 0; and math "$argv[1]"; or echo 20)
set current_unix_timestamp (date "+%s")
# Get time since last sleep / suspend / hibernate
set resume_entry (grep sinceresume /var/log/syslog | tail -n 1)
set resume_date (echo "$resume_entry" | awk '{print $1, $2, $3}')
set resume_ts (date -d "$resume_date" "+%s")
set minutes_since_resume (math "($current_unix_timestamp - $resume_ts) / 60")
# Get time since session / last unlock
switch "$XDG_SESSION_DESKTOP"
case ubuntu
set session_entry (journalctl -u session-2.scope | grep "gkr-pam: unlocked login keyring" | tail -n 1)
case pantheon
set session_entry (journalctl -u systemd-logind.service | grep "New session" | tail -n 1)
case '*'
echo "Unsupported XDG_SESSION_DESKTOP $XDG_SESSION_DESKTOP!"
exit 1
end
set session_date (echo "$session_entry" | awk '{print $1, $2, $3}')
set session_ts (date -d "$session_date" "+%s")
set minutes_since_session (math "($current_unix_timestamp - $session_ts) / 60")
set minutes (math floor (math min $minutes_since_session,$minutes_since_resume ))
if test $minutes -gt $display_threshold
echo "$minutes"m
end
I've added this to my shell startup.