Closed sanidhya-r closed 1 year ago
You'll need to install the trap
as part of the shell process you're running; here's a minimal example:
ttab 'trap ctrl_c INT; ctrl_c() { echo "Cleaning up... press Enter to exit"; read; exit 1; }; echo Press Enter to exit:; read; exit 0'
Note: This should work with Bash and Zsh. You can also use the shell executable explicitly, by placing bash -c
before the command string, but that will call via your default shell, and when your command exits you'll be in that default shell session (the advantage, however, is that you can check your command's exit code).
@mklement0 really appreciate the quick response. Thanks for the suggestion, it works as expected.
Glad to hear it, @sani-Alpha; my pleasure.
Scenario: I have a script that edits a few files and runs the npm project. If it was all part of one script, i could trap the interrupt (ctrl+c) and perform a custom clean up function that may checkout or delete files.
Problem: Since, on using ttab, a new window or tab is opened, i can't assign the same trap function to the new tab or window since the context is lost. Hence, can't perform clean up on interruption.
Proposal: Maybe if there is a way to attach a function or set of actions when an interrupt happens.
this is how i was trapping the interrupt.
this is the clean up function, that would checkout . to remove changes to tracked files and delete untracked files