f82982006717

More
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 10 Jun 2019 17:33:39 -0400
parents 4bff92ca5297
children e4bcc3509374 06a5d5a71a89
branches/tags (none)
files bin/saym bin/slock-post-lock bin/slock-post-unlock bin/tea stumpwmrc

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/saym	Mon Jun 10 17:33:39 2019 -0400
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+say "$@"
+echom "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/slock-post-lock	Mon Jun 10 17:33:39 2019 -0400
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+touch /tmp/.posture-pause
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/slock-post-unlock	Mon Jun 10 17:33:39 2019 -0400
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+rm -f /tmp/.posture-pause
--- a/bin/tea	Mon Jun 10 12:11:04 2019 -0400
+++ b/bin/tea	Mon Jun 10 17:33:39 2019 -0400
@@ -3,4 +3,4 @@
 set -euo pipefail
 
 sleep "$1"s
-say 'The tea is ready.'
+saym 'The tea is ready.'
--- a/stumpwmrc	Mon Jun 10 12:11:04 2019 -0400
+++ b/stumpwmrc	Mon Jun 10 17:33:39 2019 -0400
@@ -82,11 +82,99 @@
   `(case *host* ,@clauses))
 
 
-(defun speak (text)
+(defcommand speak (text)
+    ((:string "Text: "))
   (message text)
   (run-shell-command (format nil "~~/src/dotfiles/bin/say '~A'" text)))
 
 
+(defun seconds->hours (seconds)
+  (/ seconds 60 60))
+
+(defun hours->seconds (hours)
+  (* hours 60 60))
+
+
+;;;; Posture ------------------------------------------------------------------
+(defparameter *posture-thread* nil)
+(defparameter *posture-should-stop* nil)
+(defparameter *posture-paused* nil)
+(defparameter *posture-snooze* nil)
+(defparameter *posture-current* 30)
+(defparameter *posture-min* 5)
+(defparameter *posture-max* (hours->seconds 2))
+
+(defun posture-paused-p ()
+  ;; this is the dumbest shit ever, but I can't figure out how to call into
+  ;; stumpish from the setguid slock process
+  (or *posture-paused* (probe-file "/tmp/.posture-pause")))
+
+(defun posture-snoozed-p ()
+  (and *posture-snooze*
+       (< (get-universal-time) *posture-snooze*)))
+
+(defcommand posture-pause () ()
+  (message "Pausing posture.")
+  (setf *posture-paused* t))
+
+(defcommand posture-unpause () ()
+  (message "Unpausing posture.")
+  (setf *posture-paused* nil))
+
+(print *posture-paused*)
+
+(defcommand posture-toggle-pause () ()
+  (if (setf *posture-paused* (not *posture-paused*))
+    (message "Posture is now paused.")
+    (message "Posture is now unpaused.")))
+
+(defcommand posture-snooze (hours)
+    ((:number "Snooze for how many hours? "))
+  (setf *posture-snooze* (+ (hours->seconds hours) (get-universal-time))))
+
+(defun posture-update (delta)
+  (setf *posture-current*
+        (clamp *posture-min* *posture-max* (* *posture-current* delta))))
+
+(defun posture-query ()
+  (speak "Is your posture okay?"))
+
+(defcommand posture-answer-yes () ()
+  (message "Good work.")
+  (posture-update 3/2))
+
+(defcommand posture-answer-no () ()
+  (message "Try harder.")
+  (posture-update 1/2))
+
+(defun posture% ()
+  (if *posture-should-stop*
+    nil
+    (progn (unless (or (posture-paused-p) (posture-snoozed-p))
+             (posture-query)
+             (sleep 10))
+           *posture-current*)))
+
+(defun posture-running-p ()
+  (and *posture-thread* (sb-thread:thread-alive-p *posture-thread*)))
+
+(defcommand posture-stop () ()
+  (setf *posture-should-stop* t))
+
+(defcommand posture-start () ()
+  (setf *posture-should-stop* nil)
+  (if (posture-running-p)
+    (message "Posture loop was already running.")
+    (setf *posture-thread*
+          (sb-thread:make-thread
+            (lambda ()
+              (loop :for seconds = (posture%)
+                    :while seconds
+                    :do (sleep seconds))
+              (message "Posture loop exiting."))
+            :name "Posture thread"))))
+
+
 ;;;; Regroup ------------------------------------------------------------------
 (defparameter *class-groups*
   '(("jetbrains-idea-ce" . "ij"))
@@ -400,7 +488,13 @@
 (define-top-keys ;; timers
   ("s-F7"  "tea-timer")
   ("s-F9"  "run-pop-timer")
-  ("s-F10" "set-pop-timer"))
+  ("s-F10" "set-pop-timer")
+  ("s-p"   "posture-start")
+  ("s-P"   "posture-stop")
+  ("s-y"   "posture-answer-yes")
+  ("s-n"   "posture-answer-no")
+  ("s-\\"  "posture-toggle-pause")
+  ("s-o"   "posture-snooze"))
 
 (define-top-keys ;; stump
   ("Pause" "exec st") ; jesus christ