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 #!/bin/bash
# Theme menu for Omarchy
# Provides an interactive dmenu to switch between available themes
THEMES_DIR="$HOME/.config/omarchy/themes/" THEMES_DIR="$HOME/.config/omarchy/themes/"
CURRENT_THEME_DIR="$HOME/.config/omarchy/current/theme" CURRENT_THEME_DIR="$HOME/.config/omarchy/current/theme"
CURRENT_THEME_NAME=$(basename "$(realpath "$CURRENT_THEME_DIR")")
# Show theme selection menu and apply changes # Build themes list with pretty display names
show_theme_menu() { mapfile -t themes < <(
# Get current theme name find "$THEMES_DIR" -mindepth 1 -maxdepth 1 -type f -o -type l | while read -r path; do
if [[ -e "$CURRENT_THEME_DIR" ]]; then filename=$(basename "$path")
CURRENT_THEME_NAME=$(basename "$(realpath "$CURRENT_THEME_DIR")") display_name=$(echo "$filename" | sed -E 's/(^|-)([a-z])/\1\u\2/g; s/-/ /g')
else
CURRENT_THEME_NAME="unknown" if [[ "$filename" == "$CURRENT_THEME_NAME" ]]; then
fi echo "<i>$display_name</i>"
else
# Build menu options from available themes echo "$display_name"
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 fi
done done | sort
)
# Add current theme to the top of menu # Show Wofi menu (with markup support)
local wofi_input=$'\uf0a9 '"${CURRENT_THEME_NAME}" selection=$(printf '%s\n' "${themes[@]}" | wofi \
for theme in "${filtered_themes[@]}"; do --show dmenu \
wofi_input+="\n${theme}" --allow-markup \
done --width 150 \
--height 300 \
# Display theme selection menu -O alphabetical \
local selection=$(echo -e "$wofi_input" | wofi \ --style ~/.local/share/omarchy/default/wofi/select.css)
--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 # Remove any Pango markup before converting back to filename
if [[ -z "$selected_theme" || "$selected_theme" == "$CURRENT_THEME_NAME" ]]; then clean_selection=$(echo "$selection" | sed -E 's/<[^>]+>//g')
exit 0
fi
# Apply the new theme with omarchy-theme-set # Convert to lowercase and dash-separated: "Tokyo Night" -> "tokyo-night"
"$HOME/.local/share/omarchy/bin/omarchy-theme-set" "$selected_theme" selected_theme=$(echo "$clean_selection" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
}
# Apply the selected theme
"$HOME/.local/share/omarchy/bin/omarchy-theme-set" "$selected_theme"
# Main execution
show_theme_menu