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/colorpicker b/colorpicker deleted file mode 100755 index 1f79cb4..0000000 --- a/colorpicker +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# -# https://unix.stackexchange.com/a/523805 - -grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- 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}" diff --git a/platform_profile b/platform_profile deleted file mode 100755 index de7d6fc..0000000 --- a/platform_profile +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -case "${1}" in - get) - head -c1 /sys/firmware/acpi/platform_profile | tr '[:lower:]' '[:upper:]' - ;; - toggle) - current="$(cat /sys/firmware/acpi/platform_profile)" - choices="$(cat /sys/firmware/acpi/platform_profile_choices)" - next="$(echo "${choices} ${choices}" | tr \ \\n | grep -A1 "${current}" | tail -n+2 | head -n1)" - echo "${next}" | sudo tee /sys/firmware/acpi/platform_profile -esac diff --git a/toggle_displays.clj b/toggle_displays.clj deleted file mode 100755 index c12a079..0000000 --- a/toggle_displays.clj +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env -S bb -(ns toggle-displays - (:require [clojure.edn :as edn] - [clojure.java.io :as io] - [clojure.java.shell :refer [sh]] - [babashka.fs :as fs])) - -(def state-file - (fs/path - (System/getenv "XDG_RUNTIME_DIR") - (str (fs/file-name (or (System/getProperty "babashka.file") *file*)) ".state"))) - -(defn get-state! - [] - (if (fs/exists? state-file) - (some->> - (->> state-file - fs/unixify - io/reader - java.io.PushbackReader. - edn/read)) - (some->> - (sh "journalctl" "--user" "--unit" "kanshi.service" "--reverse" "--lines" "1") - ;; {:exit 0, :out "Mar 06 07:39:48 aegir kanshi[3318847]: configuration for profile 'kvm-1' applied\n", :err ""} - :out - (re-find #"configuration for profile '(.+?)' applied") - (second) - (keyword)))) - -(defn save-state! - [state] - (spit (fs/unixify state-file) state)) - -(defn apply-state! - [state] - (sh "kanshictl" "switch" (name state))) - -(defn next-state - [state] - (let [modes (apply concat (repeat 2 [:kvm-left - :kvm-right - :single]))] - (nth modes (inc (.indexOf modes state))))) - -(defn -main - [& [toggle?]] - (when toggle? - (let [state (get-state!) - state* (next-state state)] - (apply-state! state*) - (save-state! state*)))) - -(when (= *file* (System/getProperty "babashka.file")) - (apply -main *command-line-args*)) diff --git a/toggle_theme b/toggle_theme index f308e16..51f847c 100755 --- a/toggle_theme +++ b/toggle_theme @@ -6,13 +6,12 @@ [babashka.fs :as fs])) (def themes - {:light {:emacs "doom-oksolar-light" - :gnome "Adwaita" - :kitty "Doom OKsolar Light"} - - :dark {:emacs "doom-opera" - :gnome "Adwaita-dark" - :kitty "Default"}}) + {:emacs + {:dark "doom-opera" + :light "doom-oksolar-light"} + :gnome + {:dark "Adwaita-dark" + :light "Adwaita"}}) (def theme-preferences ["gtk" @@ -37,9 +36,8 @@ "get" (println (name (current-theme))) "toggle" - (let [next-scheme (next-theme) - next-themes (next-scheme themes) - gnome-theme (:gnome next-themes)] + (let [switch-to (next-theme) + gnome-theme ((:gnome themes) switch-to)] ;; https://askubuntu.com/questions/1464937/inconsistent-dark-theme-for-gtk-apps-on-23-04 ;; ;; $ gsettings get org.gnome.desktop.interface color-scheme @@ -52,16 +50,16 @@ ;; [["org.gnome.desktop.interface" "gtk-theme"] ;; ["org.gnome.desktop.wm.preferences" "theme"]] + (run! #(sh "gsettings" "set" "org.gnome.desktop.interface" (str % "-theme") gnome-theme) theme-preferences) - (sh "gsettings" "set" "org.gnome.desktop.interface" "color-scheme" (str "prefer-" (name next-scheme))) + (sh "gsettings" "set" "org.gnome.desktop.interface" "color-scheme" (str "prefer-" (name (next-theme)))) (sh "gsettings" "set" "org.gnome.desktop.wm.preferences" "theme" gnome-theme) (run! - #(sh "emacsclient" "--socket-name" % "--eval" (str "(load-theme '" (:emacs next-themes) ")")) + #(sh "emacsclient" "--socket-name" % "--eval" (str "(load-theme '" ((:emacs themes) switch-to) ")")) (map str (fs/list-dir (fs/file (System/getenv "XDG_RUNTIME_DIR") "emacs")))) - (sh "kitty" "+kitten" "themes" "--reload-in=all" (:kitty next-themes)) nil) false) diff --git a/ymmw b/ymmw deleted file mode 100644 index 2f9f85f..0000000 --- a/ymmw +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python3 -"""Re-format YAML passed on stdin or read from any arguments.""" - -import yaml -import sys - - -# https://stackoverflow.com/a/72265455 -def str_presenter(dumper, data): - if len(data.splitlines()) > 1 or "\n" in data: - text_list = [line.rstrip() for line in data.splitlines()] - fixed_data = "\n".join(text_list) - return dumper.represent_scalar("tag:yaml.org,2002:str", fixed_data, style="|") - return dumper.represent_scalar("tag:yaml.org,2002:str", data) - - -yaml.add_representer(str, str_presenter) - - -def ymmw(files): - if not files: - files=[sys.stdin] - - for f in files: - try: - print(f) - print(yaml.dump(yaml.load(open(f) if not f == sys.stdin else f, Loader=yaml.FullLoader)), end='') - except OSError as ex: - sys.exit(f"""ERROR: Couldn't read input from stdin, or couldn't write output to stdout. Exiting. - -{ex}""") - -if __name__ == '__main__': - ymmw(sys.argv[1:])