diff options
| author | Ja.KooLit <85185940+JaKooLit@users.noreply.github.com> | 2025-07-25 19:22:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-25 19:22:08 +0900 |
| commit | fc2d3f172f437082324aca858185bffbfd9e5c79 (patch) | |
| tree | e8afcb5b15fb5fcc0f5f54fa931466003c0dbb4a | |
| parent | 1cf593996c75e0cbb563648538ab6e3b3b85355d (diff) | |
| parent | 637025eeb60391e5cc17c883aa6ee95799acac76 (diff) | |
Merge pull request #773 from JaKooLit/main
Main to development
| -rwxr-xr-x | config/hypr/scripts/WaybarLayout.sh | 49 | ||||
| -rwxr-xr-x | config/hypr/scripts/WaybarStyles.sh | 49 |
2 files changed, 63 insertions, 35 deletions
diff --git a/config/hypr/scripts/WaybarLayout.sh b/config/hypr/scripts/WaybarLayout.sh index 0bea6ffe..955432fc 100755 --- a/config/hypr/scripts/WaybarLayout.sh +++ b/config/hypr/scripts/WaybarLayout.sh @@ -11,32 +11,47 @@ SCRIPTSDIR="$HOME/.config/hypr/scripts" rofi_config="$HOME/.config/rofi/config-waybar-layout.rasi" msg=' 🎌 NOTE: Some waybar LAYOUT NOT fully compatible with some STYLES' -# Function to display menu options -menu() { - options=() - while IFS= read -r file; do - options+=("$(basename "$file")") - done < <(find -L "$waybar_layouts" -maxdepth 1 -type f -exec basename {} \; | sort ) - - printf '%s\n' "${options[@]}" -} - # Apply selected configuration apply_config() { ln -sf "$waybar_layouts/$1" "$waybar_config" "${SCRIPTSDIR}/Refresh.sh" & } -# Main function main() { - choice=$(menu | rofi -i -dmenu -config "$rofi_config" -mesg "$msg") + # Resolve current symlink target and basename + current_target=$(readlink -f "$waybar_config") + current_name=$(basename "$current_target") + + # Build sorted list of available layouts + mapfile -t options < <( + find -L "$waybar_layouts" -maxdepth 1 -type f -printf '%f\n' | sort + ) + + # Mark and locate the active layout + default_row=0 + for i in "${!options[@]}"; do + if [[ "${options[i]}" == "$current_name" ]]; then + options[i]="👉 ${options[i]}" + default_row=$i + break + fi + done + + # Launch rofi with the annotated list, pre‑selecting the active row + choice=$(printf '%s\n' "${options[@]}" \ + | rofi -i -dmenu \ + -config "$rofi_config" \ + -mesg "$msg" \ + -selected-row "$default_row" + ) + + # Exit if nothing chosen + [[ -z "$choice" ]] && { echo "No option selected. Exiting."; exit 0; } - if [[ -z "$choice" ]]; then - echo "No option selected. Exiting." - exit 0 - fi + # Strip marker before applying + choice=${choice% ⮕} - case $choice in + case "$choice" in "no panel") pgrep -x "waybar" && pkill waybar || true ;; diff --git a/config/hypr/scripts/WaybarStyles.sh b/config/hypr/scripts/WaybarStyles.sh index 246a66a2..20f0873b 100755 --- a/config/hypr/scripts/WaybarStyles.sh +++ b/config/hypr/scripts/WaybarStyles.sh @@ -11,33 +11,46 @@ SCRIPTSDIR="$HOME/.config/hypr/scripts" rofi_config="$HOME/.config/rofi/config-waybar-style.rasi" msg=' 🎌 NOTE: Some waybar STYLES NOT fully compatible with some LAYOUTS' -# Function to display menu options -menu() { - options=() - while IFS= read -r file; do - if [ -f "$waybar_styles/$file" ]; then - options+=("$(basename "$file" .css)") - fi - done < <(find -L "$waybar_styles" -maxdepth 1 -type f -name '*.css' -exec basename {} \; | sort ) - - printf '%s\n' "${options[@]}" -} - # Apply selected style apply_style() { ln -sf "$waybar_styles/$1.css" "$waybar_style" "${SCRIPTSDIR}/Refresh.sh" & } -# Main function main() { - choice=$(menu | rofi -i -dmenu -config "$rofi_config" -mesg "$msg") + # resolve current symlink and strip .css + current_target=$(readlink -f "$waybar_style") + current_name=$(basename "$current_target" .css) + + # gather all style names (without .css) into an array + mapfile -t options < <( + find -L "$waybar_styles" -maxdepth 1 -type f -name '*.css' \ + -exec basename {} .css \; \ + | sort + ) + + # mark the active style and record its index + default_row=0 + for i in "${!options[@]}"; do + if [[ "${options[i]}" == "$current_name" ]]; then + options[i]="👉 ${options[i]}" + default_row=$i + break + fi + done + + # launch rofi with the annotated list and pre‑selected row + choice=$(printf '%s\n' "${options[@]}" \ + | rofi -i -dmenu \ + -config "$rofi_config" \ + -mesg "$msg" \ + -selected-row "$default_row" + ) - if [[ -z "$choice" ]]; then - echo "No option selected. Exiting." - exit 0 - fi + [[ -z "$choice" ]] && { echo "No option selected. Exiting."; exit 0; } + # remove annotation and apply + choice=${choice% ⮕} apply_style "$choice" } |
