How to stop pressing ctrl+c from closing the gnome terminal?
gnome-terminal --tab --title="watch reason" --command="bash -c 'yarn start'"
Running this command would open up a new terminal an run the script start.
But on pressing control+c the terminal closes.
How can this be prevented so that pressing control+c would stop the script but the terminal does not close.
Solution 1:
I also had this problem and the solution is to trap the Ctrl+C.
When Ctrl+C is pressed, you want the terminal to return to bash as if you had typed in the command manually. You can trap the Ctrl+C signal (INT) and run exec bash
instead.
This would look like:
gnome-terminal --tab --title="watch reason" --command="bash -c 'endyarnstart() { exec bash; }; trap endyarnstart INT; yarn start;'"
This will call the function endyarnstart when you press Ctrl+C, which will start bash and the terminal will behave as normal from then on.