LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Can you dynamically set the title of new tabs in gnome terminal? (https://www.linuxquestions.org/questions/linux-general-1/can-you-dynamically-set-the-title-of-new-tabs-in-gnome-terminal-576681/)

hroit 08-13-2007 03:04 AM

Can you dynamically set the title of new tabs in gnome terminal?
 
It's really handy to have tabs in gnome terminal, and I often use several. Often, however, I lose track of who's who.

Unlike, say, a browser, gnome-terminal keeps the same default title on all tabs. Yet, under the Title and Command tab (edit - current profile), it says:
Quote:

The command running inside a terminal may dynamically set a new title

an option which I enable.

According to
Code:

man gnome-terminal
it is possible to use
Code:

gnome-terminal -t <my_title>
to get a new window with the desired title.

This indeed works fine.

Now, I'd like to be able to set the title of a new tab.
While a new tab can be opened either from the menus or from the keyboard, commands seem to only open new windows. So, I can not use the -t flag to set the title of a new tab...

Is there a way of doing this which escapes me?

Thanks.

jackn

raskin 08-13-2007 05:21 AM

First, maybe clicking or double-clicking or right-clicking on tab caption will allow you to set its caption after it is open. Also I have a script
Code:

\echo -e "\x1B]2;$1\x07";
(when script is run, its argument is substituted instead of $1). It changes window caption for xterm and tab captions in tabbed terminals I tried it on. Try this script. (It outputs an escape sequence which is interpreted by whatever draws the console. Text console driver ignores it and X11 terminal emulators change session caption).

hroit 08-13-2007 05:56 PM

I've tried the command raskin provided. I wasn't able to get it to work. Maybe I don't know how to. I provided an argument both after the semicolon and with the semicolon removed. I also tried to remove the leading slash.

As to the answer, I've made some progress.

A simple way is to use the menus: Terminal - set title (which can be done without leaving the keyboard: Alt-t, s).

As to the command line, Mariano Suárez-Alvarez, one of the two authors of gnome-terminal kindly provided the following answer:
Quote:

You can use the xterm control sequences to set the window title:
ESC ] 2 ; your_title BEL

For example,

echo -e '\033]2;Hello\007'

will make 'Hello' to be your title (the 2 means 'set both the window
title and the icon title; other values are 0 and 1 which only affect
one of them)
I only understand this very paritally - an xterm control sequence is provided first in principle, and then a concrete example, which solves the current problem.
I've tried it and it works very well.

The command line, as opposed to the menus, has the advantage of allowing the setting up of a simple alias.

raskin's script is similar to Mariano's command.

The -e flag in the 'echo' command allows 'echo' to understand escape backslashes.

Thank you for your help, raskin.

Sorry about the double post, acid kewpie. I wasn't trying to get attention, I thought I was an editing, not reposting.

jackn

raskin 08-14-2007 02:58 AM

Really my command should do exactly the same as Alvarez's ... It just uses another notation for nonprintables (and backslash crept in my script and was left unnoticed because it does not change behavior). Try
Code:

echo -e '\033]2;Hello\007' | hexdump
and post output.

hroit 08-14-2007 11:51 AM

Here you go, raskin:

Code:

~$ echo -e '\033]2;Hello\007' | hexdump
0000000 5d1b 3b32 6548 6c6c 076f 000a         
000000b


raskin 08-14-2007 11:59 AM

Try running the same command ( echo -e '\033]2;Hello\007' ) in xterm. Will its caption change? If exactly the same command changes xterm's caption, but doesn't affect gnome-terminal, I would suspect bug in gnome-terminal (possibly introduced by distribution).

hroit 08-15-2007 02:43 AM

The command you had me run works both in xterm and in gnome-terminal.

I'm not sure what the purpose of this experiment was, as it's the command that I used to begin with, and that worked, in gnome-terminal.

Could you enlighten me a bit on what's going here with the xterm control sequences and hexdump, or where I could find out more about that?

I have no idea what's going on it wouldn't hurt to learn a thing or two.

jackn

raskin 08-15-2007 02:47 AM

Sorry, then I just misunderstood you. From your post I thought you had some problem (now I see that I misread it), and fell into standard escape-code debugging procedure. Sorry once again...

hroit 08-15-2007 11:49 PM

Thanks for your help and attention, raskin.

jackn

hroit 08-23-2007 03:22 PM

Just to complete this thread with what I've learned since, which might come in handy.

Obviously, there are menu options for this, accessible with the mouse: Terminal - Set Title.
More interestingly, like other menu items, this is accessible from the keyboard: Alt+t for the 'Terminal' menu, then 's' for 'Set title'.

Nicer yet, as the help manual says, the 'grave' (as in the French accent, also known as the 'backtick') key, directly gives rise to the 'Set title' dialogue box.

Nicest of all, key bindings for all such menu items can be easily set. Once the menu is dropped down and the item is highlighted, any key combination (other than the one activating the item) entered will become a shortcut.
The shortcut just entered will figure to the right of the menu item, as shortcuts usually do.
Changed your mind? Just type in another one. Finally want none? Hit backspace, and the shortcut is blank.

jackn


All times are GMT -5. The time now is 03:56 AM.