Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
Does it have to be a command? Because the gnome-terminal GUI works well for that. –  kikjezrous Apr 10 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. –  destiel starship Apr 10 at 15:47
    
Ah, I'll edit my answer. –  kikjezrous Apr 10 at 15:49

4 Answers 4

up vote 3 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
Marking this as the right answer, since it's the simplest one. :-) –  destiel starship Apr 10 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! –  destiel starship Apr 16 at 11:06
1  
No problem, it's how it works :) –  Sylvain Pineau Apr 16 at 11:08

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.

share|improve this answer

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

share|improve this answer
    
Note that you'll have to do this for every defined profiles –  Sylvain Pineau Apr 10 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.