Time Since Last Resume
It's handy to know when to take a break.
Log the time when the system resumes from standby / sleep / hibernation
Reference: System-D Suspend Service
$ nano /usr/lib/systemd/system-sleep/sinceresume
#!/bin/sh
case $1 in
post)
logger "sinceresume resumed"
;;
esac
Read the time since last resume out of the syslog
$ grep "sinceresume resumed" /var/log/syslog | tail -n 1
Read the time since start of session
$ journalctl -u systemd-logind.service | grep "New session" | tail -n 1
On Ubuntu, this ignores locking the screen. On ElementaryOS this is triggered by unlocking.
Time since last resume
$ cat ~/bin/sinceresume.sh
#!/bin/bash
# Get the current Unix timestamp
current_unix_timestamp=$(date "+%s")
# Get the syslog entry from the command line argument
resume_entry="$(grep sinceresume /var/log/syslog | tail -n 1)"
# Extract the timestamp from the syslog entry using awk
resume_ts=$(echo "$resume_entry" | awk '{print $1, $2, $3}')
# Convert the extracted timestamp to a Unix timestamp
syslog_unix_timestamp=$(date -d "$resume_ts" "+%s")
seconds_since_resume=$((current_unix_timestamp - syslog_unix_timestamp))
minutes_since_resume=$((seconds_since_resume / 60))
# get time since session (elementary-OS)
session_entry=$(journalctl -u systemd-logind.service | grep "New session" | tail -n 1)
session_ts=$(echo "$session_entry" | awk '{print $1, $2, $3}')
# Convert the extracted timestamp to a Unix timestamp
syslog_unix_timestamp=$(date -d "$session_ts" "+%s")
seconds_since_session=$((current_unix_timestamp - syslog_unix_timestamp))
minutes_since_session=$((seconds_since_session / 60))
if [ "$minutes_since_resume" -lt "$minutes_since_session" ]; then
minutes="$minutes_since_resume"
ts="$resume_ts"
else
minutes="$minutes_since_session"
ts="$session_ts"
fi
echo "$minutes minutes since your last break ($ts)"
I've added this to my shell startup.