diff options
| author | Don Williams <don.e.williams@gmail.com> | 2026-01-06 22:35:58 -0500 |
|---|---|---|
| committer | Don Williams <don.e.williams@gmail.com> | 2026-01-06 22:35:58 -0500 |
| commit | f5e75aa7d630e170b777a06aea05feb5680ef019 (patch) | |
| tree | e23f8e88921e3c74282f5922bfe839905df5d561 /config | |
| parent | 32e564b0334d9a5e89b347d93972669d3e93f830 (diff) | |
Improved error and dependency checking
Cancel behavior under set -e: rofi returns non‑zero on Escape/cancel.
Added dependency checksf wallust/rofi/notify-send aren’t installed
Combine the two sed calls into one.
Error handling always send a “changed” notification even if wallust theme fails.
Check the exit status and notify on failure.
On branch development
Your branch is up to date with 'origin/development'.
Changes to be committed:
modified: config/hypr/scripts/ThemeChanger.sh
new file: config/hypr/scripts/ThemeChanger.sh.ori
Diffstat (limited to 'config')
| -rwxr-xr-x | config/hypr/scripts/ThemeChanger.sh | 54 | ||||
| -rwxr-xr-x | config/hypr/scripts/ThemeChanger.sh.ori | 27 |
2 files changed, 67 insertions, 14 deletions
diff --git a/config/hypr/scripts/ThemeChanger.sh b/config/hypr/scripts/ThemeChanger.sh index 15534258..0843fd69 100755 --- a/config/hypr/scripts/ThemeChanger.sh +++ b/config/hypr/scripts/ThemeChanger.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash - set -euo pipefail # SPDX-FileCopyrightText: 2025-present Ahum Maitra theahummaitra@gmail.com @@ -8,20 +7,47 @@ set -euo pipefail # Repository url : https://github.com/TheAhumMaitra/cautious-waddle -# User choice -choice=$(wallust theme list \ - | sed '1d' \ - | sed 's/^- //' \ - | rofi -dmenu -p "Select Global Theme") +require() { + command -v "$1" >/dev/null 2>&1 || { + printf '%s\n' "Missing dependency: $1" >&2 + exit 127 + } +} + +require wallust +require rofi + +# notify-send is optional +have_notify() { command -v notify-send >/dev/null 2>&1; } -# If user requested to exit, then exit -[[ -z "$choice" ]] && exit 0 +# Prompt for theme; guard -e on cancel +set +e +choice="$(wallust theme list \ + | sed -e '1d' -e 's/^- //' \ + | rofi -dmenu -i -p 'Select Global Theme')" +prompt_status=$? +set -e -# Apply the theme -wallust theme "$choice" +# Exit cleanly on cancel or empty selection +if (( prompt_status != 0 )) || [[ -z "${choice}" ]]; then + exit 0 +fi -# Inform user about theme changed -notify-send "Global theme changed" "Global Theme selected $choice" +# Apply the theme and report result +if wallust theme -- "${choice}"; then + have_notify && notify-send -a ThemeChanger \ + -h string:x-dunst-stack-tag:themechanger \ + "Global theme changed" "Selected: ${choice}" -# Give warning to user for Waybar theme refresh -notify-send "Press SUPER+ALT+R to Refresh Waybar Theme" + # Try to refresh Waybar automatically; ignore failures + if command -v waybar-msg >/dev/null 2>&1; then + waybar-msg cmd reload >/dev/null 2>&1 || true + else + pkill -SIGUSR2 waybar >/dev/null 2>&1 || true + fi +else + have_notify && notify-send -u critical -a ThemeChanger \ + -h string:x-dunst-stack-tag:themechanger \ + "Failed to apply theme" "${choice}" + exit 1 +fi diff --git a/config/hypr/scripts/ThemeChanger.sh.ori b/config/hypr/scripts/ThemeChanger.sh.ori new file mode 100755 index 00000000..15534258 --- /dev/null +++ b/config/hypr/scripts/ThemeChanger.sh.ori @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# SPDX-FileCopyrightText: 2025-present Ahum Maitra theahummaitra@gmail.com +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# Repository url : https://github.com/TheAhumMaitra/cautious-waddle + +# User choice +choice=$(wallust theme list \ + | sed '1d' \ + | sed 's/^- //' \ + | rofi -dmenu -p "Select Global Theme") + +# If user requested to exit, then exit +[[ -z "$choice" ]] && exit 0 + +# Apply the theme +wallust theme "$choice" + +# Inform user about theme changed +notify-send "Global theme changed" "Global Theme selected $choice" + +# Give warning to user for Waybar theme refresh +notify-send "Press SUPER+ALT+R to Refresh Waybar Theme" |
