12

I'm trying to open up a few terminal tabs in gnome-terminal, and so far I've managed to do something, but I'm stuck now.

So, I have the following requirement:

  • Open tabs titled "X" and "Y"
  • Execute some commands
  • Keep the tabs open and ready for further use; keep the title.

So far, I managed to meet some of the requirements, but not all of them:

gnome-terminal --tab -t "X" -e "bash" --tab -t "Y" -e "top"

This opens two tabs:

  1. "X" (and then changes the title to the default title)
  2. "Y", but the tab closes as soon as I quit top.

Is there a way to open up a tab, launch bash, but not change the title? I've tried Google, but gave up.

EDIT: It doesn't has to be a command.

3
  • Does it have to be a command? Because the gnome-terminal GUI works well for that.
    – neph
    Apr 10, 2014 at 15:45
  • @kikjezrous Well, I know how to do it with keyboard shortcuts, or just right-clicking, but I have to do it whenever I get to work (and it's 6 tabs), so it's more of a convenience issue than a real necessity. Apr 10, 2014 at 15:47
  • Ah, I'll edit my answer.
    – neph
    Apr 10, 2014 at 15:49

4 Answers 4

6

To keep the tab titles you need to comment the following lines in your .bashrc:

# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
#    ;;
#*)
#    ;;
#esac

Then gnome-terminal --tab -t "X" -e "bash" --tab -t "Y" -e "top" will work as expected:

enter image description here

3
  • Marking this as the right answer, since it's the simplest one. :-) Apr 10, 2014 at 16:43
  • I've changed the accepted answer (and edited it slightly), because it better suited my requirements; this is still a great answer, though! Apr 16, 2014 at 11:06
  • 1
    No problem, it's how it works :) Apr 16, 2014 at 11:08
4

As you can see in other answers, the title of the tab is changed by the shell every time it outputs a prompt. And after executing top your tab exits because the command you told it to run finishes...

I'll do the following:

Step 1: call the terminal with shells, adding environment variables like that:

gnome-terminal --tab -t X -e "env MYTAB=X bash" --tab -t Y -e "env MYTAB=Y bash" 

Step 2: add at the end of your .bashrc the following code:

#if MYTAB is not set, return
[ -z "$MYTAB" ] && return
# reset the cursor and title 
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1="\[\e]0;$MYTAB \w\a\]$PS1"   #title: $MYTAB and current dir
# execute the commands for every tab
case "$MYTAB" in
        X)
                echo this is X
        ;;

        Y)
                echo this is Y 
                top
        ;;
esac

...which I think is easy to understand and you can modify with the command/tweaks you need. Tested and works ok; after you exit top from the tab you'll still have the prompt and the tab for you to peruse.

Screenshot (after pressing "q" in top):

screenshot

1

I'm assuming it doesn't have to be a command, and giving a totally graphical way to do this.

After launching gnome-terminal, the 'file' menu allows you to open new tabs which will have a given title assigned. That can be changed by either the 'terminal' menu or rightclicking the tab and doing it from the context menu.

Then you can open top and whatever other commands you want, it's all in the terminal, running as a normal, unbound process that's being run from any other terminal - just the desktop environment - that won't die after it feels it's done what it's supposed to do.

1
  • Using builtin gnome-terminal there is no option to set title in the context menu for tabs or any option in the 'terminal' menu. What version of terminal are you using?
    – Williams
    Oct 11, 2018 at 0:49
1

While playing around, I found that it's not the command at all - it's the profile.

Go to:

Edit | Profiles | (Default) | Edit | Title and Command 

and change the "When Terminals Set Their Own Title" option to "Keep initial title", at the bottom of the list. Now, when you launch a command with a title, it'll stick around, so your command will work properly.

enter image description here

1
  • Note that you'll have to do this for every defined profiles Apr 10, 2014 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .