Setting Terminal tab titles

Solution 1:

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

Solution 2:

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

Solution 3:

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.

Solution 4:

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