From ed3e1bd101b364124a429b6c51d58eaae43f2f4a Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Thu, 8 Oct 2026 12:41:51 -0400 Subject: [PATCH] feat(cli): add SIGINT trap and require enter to close pane after command finishes --- dot_local/bin/executable_pj-palette | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/dot_local/bin/executable_pj-palette b/dot_local/bin/executable_pj-palette index fbf759d..608a631 100755 --- a/dot_local/bin/executable_pj-palette +++ b/dot_local/bin/executable_pj-palette @@ -11,16 +11,25 @@ # run a quick-action command in ROOT # # 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 -# exits the pane keeps a shell (with the output above it) instead of closing. +# its height) in the project root. The command runs in the foreground; ctrl-c +# stops it (the output stays). Once it has exited, enter or ctrl-c closes the +# pane. set -uo pipefail 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() { - local status=$1 - printf '\n\033[2m[exit %s]\033[0m\n' "$status" - exec "${SHELL:-bash}" + local status=$1 key + printf '\n\033[2m[exit %s] enter or ctrl-c to close\033[0m' "$status" + trap 'exit 0' INT + while IFS= read -rsn1 key; do + [ -z "$key" ] && exit 0 # enter + done + exit 0 } case ${1-} in