mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 11:32:42 +00:00
feat(cli): add SIGINT trap and require enter to close pane after command finishes
This commit is contained in:
1 parent
bf1884774f
commit
ed3e1bd101
1 file changed
+14
-5
@@ -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
|
||||
|
||||
Reference in new issue
Block a user