diff --git a/bin/omarchy-theme-menu b/bin/omarchy-theme-menu index 34a3fd6..b83be48 100755 --- a/bin/omarchy-theme-menu +++ b/bin/omarchy-theme-menu @@ -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" +CURRENT_THEME_NAME=$(basename "$(realpath "$CURRENT_THEME_DIR")") -# 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") +# 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 "$display_name" + else + echo "$display_name" fi - done + done | sort +) - # 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 \?//') +# Show Wofi menu (with markup support) +selection=$(printf '%s\n' "${themes[@]}" | wofi \ + --show dmenu \ + --allow-markup \ + --width 150 \ + --height 300 \ + -O alphabetical \ + --style ~/.local/share/omarchy/default/wofi/select.css) - # Exit if the selected theme is the current theme or empty - if [[ -z "$selected_theme" || "$selected_theme" == "$CURRENT_THEME_NAME" ]]; then - exit 0 - fi +# Remove any Pango markup before converting back to filename +clean_selection=$(echo "$selection" | sed -E 's/<[^>]+>//g') - # Apply the new theme with omarchy-theme-set - "$HOME/.local/share/omarchy/bin/omarchy-theme-set" "$selected_theme" -} +# Convert to lowercase and dash-separated: "Tokyo Night" -> "tokyo-night" +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 \ No newline at end of file