mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 19:32:43 +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
|
# 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
|
||||||
|
|||||||
Reference in new issue
Block a user