43 lines
1.4 KiB
Clojure
Executable file
43 lines
1.4 KiB
Clojure
Executable file
#!/usr/bin/env bb
|
|
(ns brightness-control
|
|
"Script to toggle between light and dark themes. Inspired by
|
|
https://github.com/pedrocr/dotfiles/blob/master/.config/sway/envsetup."
|
|
(:require [clojure.java.shell :refer [sh]]
|
|
[clojure.string]
|
|
[clojure.math :as math]))
|
|
|
|
(def devices
|
|
(->> (sh "brightnessctl" "--class" "backlight" "--list")
|
|
:out
|
|
clojure.string/split-lines
|
|
(drop 1)
|
|
(partition-by #(re-find #"^Device" %))
|
|
(partition 2)
|
|
(reduce (fn [acc [[sd] [scb smb]]]
|
|
(assoc acc
|
|
(keyword (last (re-find #"^Device '(.+?)'" sd)))
|
|
|
|
{:current (Integer. (last (re-find #"Current brightness: (\d+)" scb)))
|
|
:max (Integer. (last (re-find #"Max brightness: (\d+)" smb)))}
|
|
))
|
|
{})
|
|
))
|
|
|
|
(case (some->> *command-line-args*
|
|
first)
|
|
"get" (println (name (current-theme)))
|
|
|
|
"switch"
|
|
(let [switch-to (next-theme)
|
|
gnome-theme ((:gnome themes) switch-to)]
|
|
(run!
|
|
#(sh "gsettings" "set" "org.gnome.desktop.interface" (str % "-theme") gnome-theme)
|
|
theme-preferences)
|
|
|
|
(sh "emacsclient" "-e" (str "(load-theme '" ((:emacs themes) switch-to) ")"))
|
|
nil))
|
|
|
|
|
|
(let [steps 20
|
|
tau (/ Math/PI 2)]
|
|
(map (fn [n] (* (math/sin n) 100)) (range 0 tau (/ tau steps))))
|