From f5e75aa7d630e170b777a06aea05feb5680ef019 Mon Sep 17 00:00:00 2001 From: Don Williams Date: Tue, 6 Jan 2026 22:35:58 -0500 Subject: Improved error and dependency checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- config/hypr/scripts/ThemeChanger.sh | 62 +++++++++++++++++++++++---------- config/hypr/scripts/ThemeChanger.sh.ori | 27 ++++++++++++++ 2 files changed, 71 insertions(+), 18 deletions(-) create mode 100755 config/hypr/scripts/ThemeChanger.sh.ori 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") - -# 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" +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; } + +# 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 + +# Exit cleanly on cancel or empty selection +if (( prompt_status != 0 )) || [[ -z "${choice}" ]]; then + exit 0 +fi + +# 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}" + + # 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" -- cgit v1.2.3