update scripts to be nix compatible

This commit is contained in:
Barrett Ruth 2026-02-10 20:53:05 -05:00
parent 3d2d57ddff
commit 070455ac33
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
4 changed files with 71 additions and 79 deletions

View file

@ -24,10 +24,11 @@ let
in in
{ {
home.sessionVariables = { home.sessionVariables = {
XINITRC = "${config.xdg.configHome}/X11/xinitrc";
QT_AUTO_SCREEN_SCALE_FACTOR = "1"; QT_AUTO_SCREEN_SCALE_FACTOR = "1";
}; };
dconf.enable = true;
home.packages = with pkgs; [ home.packages = with pkgs; [
wl-clipboard wl-clipboard
cliphist cliphist
@ -37,6 +38,8 @@ in
brightnessctl brightnessctl
pamixer pamixer
socat socat
glib
gsettings-desktop-schemas
(python3.withPackages (ps: [ ps.pillow ])) (python3.withPackages (ps: [ ps.pillow ]))
]; ];

View file

@ -9,16 +9,18 @@ require() {
done done
} }
require gsettings
themes="daylight themes="daylight
midnight" midnight"
as_list="$(printf "%s\n" "$themes" | awk 'NF{printf "\"%s\",", $0}' | sed 's/,$//')" # --- Selection ---
case "$(uname)" in if [ -n "$1" ]; then
Linux) theme="$1"
if [ -n "$1" ]; then else
theme="$1" case "$(uname)" in
else Linux)
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
require rofi require rofi
theme="$(printf "%s\n" "$themes" | rofi -dmenu -p 'theme')" theme="$(printf "%s\n" "$themes" | rofi -dmenu -p 'theme')"
@ -26,23 +28,13 @@ Linux)
require dmenu require dmenu
theme="$(printf "%s\n" "$themes" | dmenu -p 'select theme: ')" theme="$(printf "%s\n" "$themes" | dmenu -p 'select theme: ')"
fi fi
fi ;;
;; Darwin)
Darwin) as_list="$(printf "%s\n" "$themes" | awk 'NF{printf "\"%s\",", $0}' | sed 's/,$//')"
if [ -n "$1" ]; then
theme="$1"
else
theme="$( theme="$(
osascript <<EOF osascript <<EOF
set theList to {$as_list} set theList to {$as_list}
set chosenTheme to (choose from list theList with title "Theme" with prompt "Pick a theme" OK button name "Apply" cancel button name "Cancel" without empty selection allowed)
set chosenTheme to (choose from list theList ¬
with title "Theme" ¬
with prompt "Pick a theme" ¬
OK button name "Apply" ¬
cancel button name "Cancel" ¬
without empty selection allowed)
if chosenTheme is false then if chosenTheme is false then
return "" return ""
else else
@ -50,85 +42,75 @@ else
end if end if
EOF EOF
)" )"
fi ;;
;; *) exit 1 ;;
*) esac
exit 1 fi
;;
esac
[ -z "$theme" ] && exit 1 [ -z "$theme" ] && exit 1
echo "$themes" | grep -Fxq "$theme" || exit 1 echo "$themes" | grep -Fxq "$theme" || exit 1
# --- Platform ---
case "$(uname)" in case "$(uname)" in
Linux) Linux)
if command -v gsettings >/dev/null 2>&1; then # GTK color scheme
case "$theme" in
midnight) gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark' ;;
daylight) gsettings set org.gnome.desktop.interface color-scheme 'prefer-light' ;;
esac
# Hyprland: runtime border colors + waybar
if [ "$XDG_CURRENT_DESKTOP" = "Hyprland" ] && command -v hyprctl >/dev/null 2>&1; then
case "$theme" in case "$theme" in
midnight) midnight)
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark' hyprctl keyword general:col.active_border "rgb(e0e0e0)"
hyprctl keyword general:col.inactive_border "rgb(121212)"
;; ;;
daylight) daylight)
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light' hyprctl keyword general:col.active_border "rgb(1a1a1a)"
hyprctl keyword general:col.inactive_border "rgb(f5f5f5)"
;; ;;
*) ;;
esac esac
waybar_themes="${XDG_CONFIG_HOME:-$HOME/.config}/waybar/themes"
[ -f "$waybar_themes/$theme.css" ] && {
ln -sf "$waybar_themes/$theme.css" "$waybar_themes/theme.css"
pkill -USR2 waybar
}
fi fi
[ "$XDG_SESSION_TYPE" = "wayland" ] && {
if [ "$XDG_CURRENT_DESKTOP" = 'Hyprland' ]; then
current_theme=$(readlink "$XDG_CONFIG_HOME/hypr/theme.conf" 2>/dev/null | awk -F/ '{print $NF}' | sed 's/\.conf$//')
if [ "$current_theme" != "$theme" ]; then
ln -sf "$XDG_CONFIG_HOME/hypr/themes/$theme.conf" "$XDG_CONFIG_HOME/hypr/theme.conf"
ln -sf "$XDG_CONFIG_HOME/waybar/themes/$theme.css" "$XDG_CONFIG_HOME/waybar/themes/theme.css"
hyprctl reload
pkill -USR1 waybar
pkill -USR1 waybar
fi
elif [ "$XDG_CURRENT_DESKTOP" = 'sway' ]; then
current_theme=$(readlink "$XDG_CONFIG_HOME/sway/themes/theme" 2>/dev/null | sed 's|.*/||')
if [ "$current_theme" != "$theme" ]; then
test -f "$XDG_CONFIG_HOME/sway/themes/theme" && ln -sf "$XDG_CONFIG_HOME/sway/themes/$theme" "$XDG_CONFIG_HOME/sway/themes/theme"
swaymsg reload
fi
fi
}
test -d "$XDG_CONFIG_HOME/rofi/themes" && ln -sf "$XDG_CONFIG_HOME/rofi/themes/$theme.rasi" "$XDG_CONFIG_HOME/rofi/themes/theme.rasi"
;; ;;
Darwin) Darwin)
case "$theme" in case "$theme" in
daylight) daylight) osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to false' 2>/dev/null || true ;;
osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to false' 2>/dev/null || true midnight) osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to true' 2>/dev/null || true ;;
;;
midnight)
osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to true' 2>/dev/null || true
;;
esac esac
;; ;;
esac esac
test -d "$XDG_CONFIG_HOME/fzf/themes" && ln -sf "$XDG_CONFIG_HOME/fzf/themes/$theme" "$XDG_CONFIG_HOME/fzf/themes/theme" # --- Cross-platform ---
test -d "$XDG_CONFIG_HOME/rg/themes" && ln -sf "$XDG_CONFIG_HOME/rg/themes/$theme" "$XDG_CONFIG_HOME/rg/themes/theme"
test -d "$XDG_CONFIG_HOME/sioyek/themes" && ln -sf "$XDG_CONFIG_HOME/sioyek/themes/$theme.config" "$XDG_CONFIG_HOME/sioyek/themes/theme.config"
test -d "$XDG_CONFIG_HOME/task/themes" && ln -sf "$XDG_CONFIG_HOME/task/themes/$theme.theme" "$XDG_CONFIG_HOME/task/themes/theme.theme"
if command -v claude >/dev/null 2>&1; then # Tmux
CLAUDE_CONFIG="${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json" if [ -n "$TMUX" ]; then
claude_theme='light' tmux_themes="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/themes"
case "$theme" in [ -f "$tmux_themes/$theme.conf" ] && tmux source "$tmux_themes/$theme.conf"
daylight) tmux setenv -g THEME "$theme"
claude_theme='light'
;;
midnight)
claude_theme='dark'
;;
esac
test -f "$CLAUDE_CONFIG" && jq ".theme=\"$claude_theme\"" "$CLAUDE_CONFIG" >"$CLAUDE_CONFIG.tmp" && mv "$CLAUDE_CONFIG.tmp" "$CLAUDE_CONFIG"
fi fi
test -f ~/.zshenv && sed -i "s|^\(export THEME=\).*|\1$theme|" ~/.zshenv # Claude CLI
[ -n "$TMUX" ] && tmux setenv -g THEME "$theme" if command -v claude >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
CLAUDE_CONFIG="${CLAUDE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/claude}/.claude.json"
case "$theme" in
midnight) claude_theme='dark' ;;
daylight) claude_theme='light' ;;
esac
[ -f "$CLAUDE_CONFIG" ] && {
jq ".theme=\"$claude_theme\"" "$CLAUDE_CONFIG" > "$CLAUDE_CONFIG.tmp" &&
mv "$CLAUDE_CONFIG.tmp" "$CLAUDE_CONFIG"
}
fi
for socket in /tmp/nvim-*.sock; do # Neovim instances
test -S "$socket" && nvim --server "$socket" --remote-expr "luaeval('require(\"config.fzf_reload\").reload()')" 2>/dev/null || true for socket in /run/user/"$(id -u)"/nvim.*.0 /tmp/nvim-*.sock; do
[ -S "$socket" ] && nvim --server "$socket" --remote-expr "luaeval('require(\"config.fzf_reload\").reload()')" 2>/dev/null || true
done done

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Requires python3 with Pillow (provided by home-manager packages)
import os import os
import random import random
@ -8,7 +9,7 @@ import sys
try: try:
from PIL import Image, ImageDraw from PIL import Image, ImageDraw
except ImportError: except ImportError:
print("wp: missing dependency: pillow (pip install pillow)", file=sys.stderr) print("wp: missing dependency: pillow (should be in home-manager python3 package)", file=sys.stderr)
sys.exit(1) sys.exit(1)
HOME = os.environ["HOME"] HOME = os.environ["HOME"]

View file

@ -1,4 +1,10 @@
#!/bin/sh #!/bin/sh
# X11 utilities -- only usable under X11 sessions
[ "$XDG_SESSION_TYPE" = "x11" ] || {
echo "x: requires X11 session (current: ${XDG_SESSION_TYPE:-unknown})" >&2
exit 1
}
require() { require() {
for cmd in "$@"; do for cmd in "$@"; do