]> git.scottworley.com Git - keystroke-timestamps/commitdiff
daily-gaps.sh script
authorScott Worley <scottworley@scottworley.com>
Sat, 22 Aug 2026 16:01:48 +0000 (09:01 -0700)
committerScott Worley <scottworley@scottworley.com>
Sat, 22 Aug 2026 16:01:48 +0000 (09:01 -0700)
Changelog
daily-gaps.sh [new file with mode: 0755]
gaps.sh

index c6c8f65d15192389fafd97829e01be0edd8af4e4..ca9fbbd48919b5741ca0d6b779ec3b7dcebe93e5 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,5 +1,6 @@
 ## [Unreleased]
 - More portable shebangs
+- Demo daily-gaps.sh script
 
 
 ## [1.1.0] - 2026-08-21
diff --git a/daily-gaps.sh b/daily-gaps.sh
new file mode 100755 (executable)
index 0000000..090fe6f
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+# Report gaps that contain the target time
+
+target=${1:-3:30}
+threshold=${2:-3600}
+LOGFILE="${3:-$HOME/keystroke-timestamps.log}"
+
+awk -vtarget="$(date -d "$target" '+%H %M %S')" -vthreshold="$threshold" -vtime_fmt="%F %T" '
+  function first_target_after(t) {
+    # TODO: Be smarter for targets near DST changes.  :(
+    target_on_t_day = mktime(strftime("%Y %m %d ", t) target)
+    target_on_prev_day = mktime(strftime("%Y %m %d ", target_on_t_day - 86400) target)
+    target_on_next_day = mktime(strftime("%Y %m %d ", target_on_t_day + 86400) target)
+    if (target_on_prev_day > t) { return target_on_prev_day }
+    if (target_on_t_day    > t) { return target_on_t_day    }
+    return target_on_next_day
+  }
+  $1 <= 67767976233561595 {
+    if (prev && $1 - prev > threshold && $1 > first_target_after(prev)) {
+      print(strftime(time_fmt, prev), "to", strftime(time_fmt, $1), "was", $1 - prev)
+    }
+    prev = $1
+  }' "$LOGFILE"
diff --git a/gaps.sh b/gaps.sh
index 7f8de73e38026a6886491c06e5411269e6e047a7..e2144e1331f1d66285561501d330350f3471d98b 100755 (executable)
--- a/gaps.sh
+++ b/gaps.sh
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+set -e
+
 threshold=${1:-3600}
 LOGFILE="${2:-$HOME/keystroke-timestamps.log}"