Reputation: 5927
I am working on a Ubuntu VM where i have multiple terminal windows open at the same time. I switch between them many times and it's hard to keep track of which window has which purpose. So what I want to do is to issue some sort of command from the command line that would permanently alter the title of the window. One approach is to modify the following line in .bashrc
to, say, add the word FOO
to the title:
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@${InstName}:FOO:\w\a\]$PS1"
Then I would do source .bashrc
. The problem is that I only have one .bashrc
and many windows. So if I open two windows one after another without changing the line in .bashrc
, I'll have FOO
in both of them. So I want to issue a command from each window instead. How do I do that?
NOTE: The stuff around FOO
in the PS1
line above is important too, so what I want is to essentially add a window-specific string to the generic PS1
specification above.
Upvotes: 1
Views: 3013
Reputation: 1412
This similar question has a far better answer from "trtayloriv", explaining the most direct way to set it and why it doesn't work until you edit the PS1 environment variable which is set in the "~/.bashrc" file. Then also how you can add a function to avoid having to remember the cryptic echo command.
This is different (perhaps better) because instead of setting the title outside/before starting the terminal/script you can more decisively set the title as part of the script itself. For me at least that's more deterministic because my scripts already know what they are doing and I simply want them to identify themselves clearly no matter how I ran them (double-click from desktop or start via another terminal session).
Upvotes: 0
Reputation: 4226
Use $$
to get the PID:
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@${InstName}:PID$$:\w\a\]$PS1"
Edit
you can define a variable mytitle
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@${InstName}:$mytitle:\w\a\]$PS1"
and spawn new terminals with new title
export mytitle=WINDOW1 && gnome-terminal
export mytitle=WINDOW2 && gnome-terminal
Upvotes: 1
Reputation: 2094
It is not entirely clear if you want to change the window title or the tab title. For the window title, see https://askubuntu.com/questions/22413/how-to-change-gnome-terminal-title wmctrl -r :ACTIVE: -N "MyWindowTitle"
Upvotes: 0