feat(cli): add SIGINT trap and require enter to close pane after command finishes

This commit is contained in:
Prad Nukala committed 2026-10-08 12:41:51 -04:00
1 parent bf1884774f
commit ed3e1bd101
1 file changed
+14 -5
+14 -5
View File
@@ -11,16 +11,25 @@
# run a quick-action command in ROOT # run a quick-action command in ROOT
# #
# Every item opens a full-width split along the bottom of the window (25% of # Every item opens a full-width split along the bottom of the window (25% of
# its height) in the project root. The command runs in the foreground; when it # its height) in the project root. The command runs in the foreground; ctrl-c
# exits the pane keeps a shell (with the output above it) instead of closing. # stops it (the output stays). Once it has exited, enter or ctrl-c closes the
# pane.
set -uo pipefail set -uo pipefail
self=$(readlink -f "$0") self=$(readlink -f "$0")
# While the task runs, ctrl-c reaches only the task: with SIGINT trapped,
# bash survives the child's death instead of exiting along with it.
trap : INT
finish() { finish() {
local status=$1 local status=$1 key
printf '\n\033[2m[exit %s]\033[0m\n' "$status" printf '\n\033[2m[exit %s] enter or ctrl-c to close\033[0m' "$status"
exec "${SHELL:-bash}" trap 'exit 0' INT
while IFS= read -rsn1 key; do
[ -z "$key" ] && exit 0 # enter
done
exit 0
} }
case ${1-} in case ${1-} in