fix(moonup): keep terminal open on errors via EXIT trap

The previous end-of-script `read` never ran when `set -e` aborted mid-way
(pacman conflict, paru failure, Ctrl+C), so foot closed on errors —
exactly when the user most needs to see the output.

Move the pause into a trap on EXIT, gated by `MOONUP_WAIT=1` so CLI use
stays non-interactive. Waybar on-click now sets the env var.
This commit is contained in:
nevaforget 2026-04-22 08:23:25 +02:00
parent c2cee85488
commit 373bfd4a9b
2 changed files with 16 additions and 7 deletions

View File

@ -217,7 +217,7 @@
},
"exec": "moonarch-waybar-updates",
"interval": 60,
"on-click": "foot moonarch-update"
"on-click": "foot env MOONUP_WAIT=1 moonarch-update"
},
"custom/notification": {
"tooltip": true,

View File

@ -19,6 +19,21 @@ _t() {
esac
}
# Pause on exit when launched from a GUI (Waybar sets MOONUP_WAIT=1).
# Runs via trap so it fires even when `set -e` aborts the script mid-way.
_pause_on_exit() {
local rc=$?
if [[ -n "${MOONUP_WAIT:-}" && -t 0 ]]; then
echo
if (( rc != 0 )); then
echo -e "\e[1;31m[Moonarch ERROR]\e[0m $(_t "Exited with error (code $rc)" "Mit Fehler beendet (Code $rc)")" >&2
fi
read -n 1 -s -r -p "$(_t "Press any key to close..." "Beliebige Taste drücken zum Schließen …")" || true
echo
fi
}
trap _pause_on_exit EXIT
# --- Helper functions ---
log() {
@ -120,9 +135,3 @@ log ""
log "============================================"
log " $(_t "Moonarch update complete!" "Moonarch-Aktualisierung abgeschlossen!")"
log "============================================"
# Keep terminal open when launched from a GUI (e.g. Waybar on-click)
if [[ -t 0 ]]; then
echo
read -n 1 -s -r -p "$(_t "Press any key to close..." "Beliebige Taste drücken zum Schließen …")"
fi