gnome-terminal -- bash --rcfile ~/gnome-terminal-scripts/test-rcfile
You should see it open a new terminal which echoes "test", waits a few seconds, then displays a new prompt. Use CTRL+C and it will kill the sleep, but still return you to the interactive prompt.
If i get it right... technically it doesn't "return to the interactive prompt" but rather continues in bash "invocation" chain (profile->)rcfile->prompt. And we hook into rcfile here.
Nice trick indeed. Thanks!
However, CTRL+C is *special* as it terminates the bash -c process in much the same way set -e does.
And, set +e does not have any effect on CTRL+C, because it's not a command exiting with a nonzero return code.
One way you could do this is by using bash --rcfile.
Create a bash script with the following contents (let's assume you save it as ~/gnome-terminal-scripts/test-rcfile):
source ~/.bashrc
echo test;sleep 2;
Then invoke gnome-terminal as follows:
gnome-terminal -- bash --rcfile ~/gnome-terminal-scripts/test-rcfile
You should see it open a new terminal which echoes "test", waits a few seconds, then displays a new prompt. Use CTRL+C and it will kill the sleep, but still return you to the interactive prompt.
...
Other alternatives include using a terminal emulator like guake, which allows you to control tabs in a running instance. So:
guake -n -g -e "echo test; sleep 2"
would spawn a new tab in guake, select that tab, and run a specified command in it (but not exit when it is done).
]]>gnome-terminal -- bash -c "echo test;sleep 2;exec bash"
But if i break the process within the 2 seconds with ctrl-c (that should be the same as an error) the window closes. I've tried 'set +e' so far but it doesn't help.
I have many bash scripts linked on the desktop (like pacman -Syu and so on) that i start with a double click. But whenever there is an error the window disappears that's kinda annoying.
Any idea how to keep the window open?
]]>