Linux Terminator – Configure Command on Startup and Keep Terminal Open

bashlinuxterminalterminator

I'm using terminator con Linux, and I have configure my ~/.config/terminator/config file to start at specific folders running certain commands

I added a ; bash (also tried with ; bash && bash || bash) at the end to prevent the terminal window from closing when the command ends

Some of them, the ones running with pnpm (node) works as expected, but others just close the terminal as soon as I ctrl-C on it, despite the ; bash

These work ok:

    [[[terminal7]]]
      type = Terminal
      ...
      directory = /home/.../app
      command = "pnpm dev:localhost; bash"
    [[[terminal8]]]
      type = Terminal
      ...
      directory = /home/.../billing
      command = "pnpm dev:localhost; bash"

these don't

    [[[terminal3]]]
      type = Terminal
      ...
      directory = /home/.../backend
      command = "make teardown && make setup; bash"
    [[[terminal4]]]
      type = Terminal
      ...
      directory = /home/.../backend
      command = "sleep 3 && cargo xtask run --config resources/configuration/dev-opensas.yaml; bash && bash || bash"

any idea what could be wrong?

Best Answer

While typically a noninteractive copy of bash will exit when it receives the SIGINT signal sent with ctrl+c, you can use the trap command to prevent this:

command = "trap : SIGINT; make teardown && make setup; trap - SIGINT; exec bash"

The : command used above is a synonym for true (conventionally used when it's intended to act as a noop). Thus, we're telling the parent shell to effectively ignore SIGINT while it's running make teardown && make setup, then putting the handling of that signal back to defaults before we run exec bash to replace the noninteractive copy of bash with a new one (which, observing itself to be attached to a TTY, should configure itself to be interactive by default).

Related Question