Closed eden-omb closed 2 years ago
@eden-omb, to quote from the manual:
Prefix such a single command with
exec
to exit the shell after the command terminates. If the tab's settings are configured to close tabs on termination of the shell, the tab will close automatically.
That is, by default a given command executes in a session of the user's default shell that stays open after the given command terminates. Terminating that command prematurely with Ctrl-C normally does not end the session as whole - only the command itself.
If the command is a call to an external utility and you prefix it with exec
, the command replaces the shell session, and Ctrl-C therefore terminates the external utility process, which typically closes the tab (but your terminal program may be configured to still keep the tab open and show information that the process terminated).
Contrast the behavior of tab sleep 5
with tab exec sleep 5
: press Ctrl-C before the 5 seconds elapse, and you should end up in an interactive session with the former command, whereas the latter (typically) closes the tab.
Note that if your default shell is PowerShell, as of v7.2.1 it does not support exec
, but support is coming in v7.3 - see https://github.com/PowerShell/PowerShell/pull/16462
Finally, you can pass multiple shell commands and end the list with exit
in order to auto-close the tab:
ttab 'sleep 5; echo after sleep; exit'
What if one specifically does not want the tab to close on CTRL+C?
I'm trying to write a script that makes starting my day a bit simpler. It will open several tabs, one for each microservice in my platform, and start each one via its npm script. I want the tabs to stay open if I CTRL+C out of them, so that I can close and restart them when code changes without having to make a new tab.
If I open the tabs in the script like this: ttab -d ../packages/client npm run dev
, when I CTRL+C out of it, the tab closes, which is not what I am trying to accomplish.
I'm testing this on Mint 20.3, which I believe is using gnome-terminal.
@barankyle, please see #43
Thanks for tracking this in an issue.
@barankyle, thanks for pointing out the problem to begin with. Fixed in v0.7.3, available via npm
(the Homebrew version hasn't been updated, because the problem doesn't affect the macOS terminals).
Worked for me after the update, thank you for making this change so quickly.
In my experiments, when I Ctrl+C out of long-running commands, it sometimes leaves the tab open, and closes it other times, apparently depending on the program. I'm not sure what's the intended default here, but this seems like behavior I'd want to set per tab anyway. Any way to add a flag for this?