Tune this up and make it prettier

This commit is contained in:
David Heinemeier Hansson
2025-07-14 21:31:58 -07:00
parent 45d6aac29c
commit bfc8d73300

View File

@ -1,55 +1,38 @@
#!/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")")
# Build themes list with pretty display names
mapfile -t themes < <(
find "$THEMES_DIR" -mindepth 1 -maxdepth 1 -type f -o -type l | while read -r path; do
filename=$(basename "$path")
display_name=$(echo "$filename" | sed -E 's/(^|-)([a-z])/\1\u\2/g; s/-/ /g')
if [[ "$filename" == "$CURRENT_THEME_NAME" ]]; then
echo "<i>$display_name</i>"
else
CURRENT_THEME_NAME="unknown"
echo "$display_name"
fi
done | sort
)
# 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 Wofi menu (with markup support)
selection=$(printf '%s\n' "${themes[@]}" | wofi \
--show dmenu \
--width 300 \
--height 225 \
--allow-markup \
--width 150 \
--height 300 \
-O alphabetical \
--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 \?//')
# Remove any Pango markup before converting back to filename
clean_selection=$(echo "$selection" | sed -E 's/<[^>]+>//g')
# Exit if the selected theme is the current theme or empty
if [[ -z "$selected_theme" || "$selected_theme" == "$CURRENT_THEME_NAME" ]]; then
exit 0
fi
# Convert to lowercase and dash-separated: "Tokyo Night" -> "tokyo-night"
selected_theme=$(echo "$clean_selection" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
# Apply the new theme with omarchy-theme-set
# Apply the selected theme
"$HOME/.local/share/omarchy/bin/omarchy-theme-set" "$selected_theme"
}
# Main execution
show_theme_menu