playground/inhibit_sleep
2024-09-14 04:16:51 +02:00

26 lines
583 B
Clojure
Executable file

#!/usr/bin/env bb
(ns inhibit-sleep
(:require [clojure.java.shell :refer [sh]]))
(defn has-lock? []
(->> (sh "systemd-inhibit")
:out
(clojure.string/split-lines)
(filter #(re-find #"inhibit-sleep" %))
seq))
(case (some->> *command-line-args*
first)
"get" (if (boolean (has-lock?))
"inhibited"
"normal")
"toggle"
(if (has-lock?)
nil
(apply sh (clojure.string/split
"systemd-inhibit \
--what=handle-lid-switch:sleep \
--why=':inhibit-sleep' \
--mode=block cat" #"\s+"))))