How can I keep the gnome-terminal open after a program closes?

31,899

Solution 1

1. First option: edit gnome-terminal settings

In gnome-terminal, go to preferences, the "Title and command" tab. Then click the drop-down list "When command finishes", choose "Keep terminal open".

enter image description here


2. If you prefer not to have an effect on all terminals

You can add bashas a last command. In my test,

Exec=gnome-terminal -e 'bash -c "gedit; echo Monkey; bash"'

did the job. In your command, you probably need to do it like:

Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key [email protected] sudo -s; bash"'


3. Keep the terminal open until you hit Enter

Another option is to place read line at the end of your commands. In that case, the terminal will stay open until you hit Enter

From my test:

Exec=gnome-terminal -e 'bash -c "gedit; echo Monkey; read line"'

Or in your command probably:

Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key [email protected] sudo -s; read line"'

Notes

  • Note that this launcher will "steel" possible other windows from gnome-terminal's own application launcher in the Unity Launcher, since this launcher calls gnome-terminalin its "main" command. Cleaner would be to add the command as a shortcut to the existing gnome-terminal launcher (or any other launcher you'd like).
  • Since the command in the launcher already calls gnome-terminal, you do not need to set Terminal=true.

Solution 2

You can do this by simply adding '$SHELL' variable at the end of your command. See below example in Exec=.... line.

[Desktop Entry]
Type=Application
Terminal=true
Name=MDS Control
Icon=utilities-terminal
Exec=gnome-terminal -e "bash -c 'Your command;$SHELL'"
Categories=Application;
Name[en_US]=MDS-Control

Solution 3

I played around with this code for a few minutes. I think I found a solution. Here is my (a bit oversimplified when it comes to the details) code:

[Desktop Entry]
Terminal=true
Type=Application
Name[en_US]=ssh
Exec=gnome-terminal -e 'bash -c "ssh"' && gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash'

Hope this helps!

I just added a line of code executing gnome-terminal with raw bash using the && command.

EDIT: I just realized someone already solved it!! Oops!

Share:
31,899

Related videos on Youtube

Rostyslav Malenko
Author by

Rostyslav Malenko

Updated on September 18, 2022

Comments

  • Rostyslav Malenko
    Rostyslav Malenko over 1 year

    I have the following shortcut which opens an SSH instance. How can I modify it so that when SSH closes, the terminal stays open?

    [Desktop Entry]
    Terminal=true
    Type=Application
    Name[en_US]=ssh
    Icon=/logo_sprite.png
    Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key [email protected] sudo -s"'
    
  • A.B.
    A.B. almost 9 years
    But this affects all terminals.
  • Jacob Vlijm
    Jacob Vlijm almost 9 years
    @A.B. It does, but is that a problem?
  • A.B.
    A.B. almost 9 years
    I would say yes.
  • Jacob Vlijm
    Jacob Vlijm almost 9 years
    @A.B. added another option.
  • Jacob Vlijm
    Jacob Vlijm almost 9 years
    @RostyslavMalenko That surprises me, but I'll try to test on 15.04
  • Jacob Vlijm
    Jacob Vlijm almost 9 years
    @RostyslavMalenko The strange thing is, it does work on my 15.04. An alternative would be to replace bash by read line, so the Exec= line would be: Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key [email protected] sudo -s; read line"' Then the terminal would only close after you hit Enter.
  • 0x2b3bfa0
    0x2b3bfa0 almost 9 years
    +1: Except the first option, you read my thoughts. ;-)
  • Jacob Vlijm
    Jacob Vlijm almost 9 years
    @Helio Thanks! That is actually a compliment :)
  • solsTiCe
    solsTiCe almost 9 years
    Why not create a special profile with "not quit as command end" and call that profile with gnome-terminal --profile=myprofilenoendcmd ?
  • Jacob Vlijm
    Jacob Vlijm almost 9 years
    @solsTiCe That is actually a nice idea!
  • MrCholo
    MrCholo over 5 years
    how to do this programmatically? Instead of using the GUI.
  • Ryan Wheale
    Ryan Wheale over 4 years
    This helped me - basically just needed to rerun the same gnome-terminal command without the -e option. I tried like 15 different techniques before landing on this one.
  • Kvothe
    Kvothe over 3 years
    It seems that no-one is looking for the behaviour that I would call keeping the terminal open. Is it possible to keep the terminal open and interactive after the command. When I try the above it stays open but stuck. I can't enter new commands.