From 547d40ff466f7111a7296981498323902f083e9e Mon Sep 17 00:00:00 2001 From: "Rune Juhl (Atea)" Date: Sat, 14 Sep 2024 04:16:51 +0200 Subject: [PATCH] brightness control, inhibit sleep, install fonts --- brightness_control | 43 +++++++++++++++++++++++++++++++++++++++++++ inhibit_sleep | 26 ++++++++++++++++++++++++++ install-atea-fonts.sh | 18 ++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 brightness_control create mode 100755 inhibit_sleep create mode 100755 install-atea-fonts.sh diff --git a/brightness_control b/brightness_control new file mode 100755 index 0000000..82d38d2 --- /dev/null +++ b/brightness_control @@ -0,0 +1,43 @@ +#!/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)))) diff --git a/inhibit_sleep b/inhibit_sleep new file mode 100755 index 0000000..45d8a0a --- /dev/null +++ b/inhibit_sleep @@ -0,0 +1,26 @@ +#!/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+")))) diff --git a/install-atea-fonts.sh b/install-atea-fonts.sh new file mode 100755 index 0000000..1d09d1c --- /dev/null +++ b/install-atea-fonts.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail + +command -v woff2_decompress + +tmp="$(mktemp -d)" +pushd "${tmp}" +for style in Light Regular Medium Bold; do + f="Inter-${style}.woff2" + wget "https://www.atea.dk/fonts/${f}" + woff2_decompress "${f}" +done + +mv ./*.ttf ~/.local/share/fonts +fc-cache -f -v +popd +rm "${tmp}"