From 45d6aac29c3381e63bfdba5bce2625a573e4fc04 Mon Sep 17 00:00:00 2001 From: Noah Penza <69229034+npenza@users.noreply.github.com> Date: Tue, 15 Jul 2025 14:17:04 +1000 Subject: [PATCH] Add Theme Menu Switcher (#154) * Add theme menu for quick theme switching * Bind theme menu * Fix current theme being selected * Replace omarchy-theme-next binding with theme menu * Add omarchy-theme-set and refactor theme menu script * Add solid black fallback if background image does not exist in current theme --- bin/omarchy-theme-menu | 55 ++++++++++++++++++++++++++++ bin/omarchy-theme-set | 47 ++++++++++++++++++++++++ default/hypr/bindings/utilities.conf | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100755 bin/omarchy-theme-menu create mode 100755 bin/omarchy-theme-set diff --git a/bin/omarchy-theme-menu b/bin/omarchy-theme-menu new file mode 100755 index 0000000..34a3fd6 --- /dev/null +++ b/bin/omarchy-theme-menu @@ -0,0 +1,55 @@ +#!/bin/bash + +# Theme menu for Omarchy +# Provides an interactive dmenu to switch between available themes + +THEMES_DIR="$HOME/.config/omarchy/themes/" +CURRENT_THEME_DIR="$HOME/.config/omarchy/current/theme" + +# Show theme selection menu and apply changes +show_theme_menu() { + # Get current theme name + if [[ -e "$CURRENT_THEME_DIR" ]]; then + CURRENT_THEME_NAME=$(basename "$(realpath "$CURRENT_THEME_DIR")") + else + CURRENT_THEME_NAME="unknown" + fi + + # Build menu options from available themes + local themes=($(find "$THEMES_DIR" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | sort)) + + # Remove the current theme from the list before building the menu + local filtered_themes=() + for theme in "${themes[@]}"; do + if [[ "$theme" != "$CURRENT_THEME_NAME" ]]; then + filtered_themes+=("$theme") + fi + done + + # Add current theme to the top of menu + local wofi_input=$'\uf0a9 '"${CURRENT_THEME_NAME}" + for theme in "${filtered_themes[@]}"; do + wofi_input+="\n${theme}" + done + + # Display theme selection menu + local selection=$(echo -e "$wofi_input" | wofi \ + --show dmenu \ + --width 300 \ + --height 225 \ + --style ~/.local/share/omarchy/default/wofi/select.css) + + # Extract theme name from selection (remove glyph and leading spaces) + local selected_theme=$(echo "$selection" | sed 's/^\s*\uf0a9 \?//') + + # Exit if the selected theme is the current theme or empty + if [[ -z "$selected_theme" || "$selected_theme" == "$CURRENT_THEME_NAME" ]]; then + exit 0 + fi + + # Apply the new theme with omarchy-theme-set + "$HOME/.local/share/omarchy/bin/omarchy-theme-set" "$selected_theme" +} + +# Main execution +show_theme_menu \ No newline at end of file diff --git a/bin/omarchy-theme-set b/bin/omarchy-theme-set new file mode 100755 index 0000000..e800f5f --- /dev/null +++ b/bin/omarchy-theme-set @@ -0,0 +1,47 @@ +#!/bin/bash + +# omarchy-theme-set: Set a theme, specified by its name. +# Usage: omarchy-theme-set + +THEMES_DIR="$HOME/.config/omarchy/themes/" +CURRENT_THEME_DIR="$HOME/.config/omarchy/current/theme" + +if [[ -z "$1" ]]; then + echo "Usage: omarchy-theme-set " >&2 + exit 1 +fi + +THEME_NAME="$1" +THEME_PATH="$THEMES_DIR/$THEME_NAME" +BACKGROUND_PATH="$HOME/.config/omarchy/backgrounds/$THEME_NAME" + +# Check if the theme entered exists +if [[ ! -d "$THEME_PATH" ]]; then + echo "Theme '$THEME_NAME' does not exist in $THEMES_DIR" >&2 + exit 2 +fi + +# Update theme symlinks +ln -nsf "$BACKGROUND_PATH" "$HOME/.config/omarchy/current/backgrounds" +ln -nsf "$THEME_PATH" "$CURRENT_THEME_DIR" + +# Trigger alacritty config reload +touch "$HOME/.config/alacritty/alacritty.toml" + +# Restart components to apply new theme +pkill -SIGUSR2 waybar +makoctl reload +hyprctl reload + +# Set new background +first_bg=$(find "$HOME/.config/omarchy/current/backgrounds/" -type f | head -n 1) +if [[ -n "$first_bg" ]]; then + ln -nsf "$first_bg" "$HOME/.config/omarchy/current/background" + pkill -x swaybg + setsid swaybg -i "$HOME/.config/omarchy/current/background" -m fill & +else + # Background does not exist for this theme - fallback to solid black. + rm -f "$HOME/.config/omarchy/current/background" + pkill -x swaybg + setsid swaybg -c '#000000' & +fi \ No newline at end of file diff --git a/default/hypr/bindings/utilities.conf b/default/hypr/bindings/utilities.conf index 0e6b1b7..6448294 100644 --- a/default/hypr/bindings/utilities.conf +++ b/default/hypr/bindings/utilities.conf @@ -5,7 +5,7 @@ bind = SUPER, K, exec, ~/.local/share/omarchy/bin/omarchy-show-keybindings # Aesthetics bind = SUPER SHIFT, SPACE, exec, pkill -SIGUSR1 waybar bind = SUPER CTRL, SPACE, exec, ~/.local/share/omarchy/bin/swaybg-next -bind = SUPER SHIFT CTRL, SPACE, exec, ~/.local/share/omarchy/bin/omarchy-theme-next +bind = SUPER SHIFT CTRL, SPACE, exec, ~/.local/share/omarchy/bin/omarchy-theme-menu # Notifications bind = SUPER, comma, exec, makoctl dismiss