You are not logged in.

#1 2011-06-22 10:59:57

indianahorst
Member
Registered: 2008-08-23
Posts: 127

How to set the title of an urxvt window?

Hello,

I have read the manpage and FAQ on the urxvt website, but my problem persists:

When I try to set the title of an urxvt window, for example:

$ urxvt -title test

then the new window shows for a second the title "test" and then switches  to "username@hostname:~".
Yes, I have

case $TERM in
   xterm*|*rxvt*|Eterm|eterm|rxvt-unicode|urxvt)
      PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
      ;;
   screen)
      PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
      ;;
esac 

in my .bashrc.

But I think, the explicit command line option "-title" should break the .bashrc, right?
The default setting by .bashrc is intentional, but in this specific case I would like to set the window title by hand.

How can I do that?

Last edited by indianahorst (2011-06-22 11:01:34)

Offline

#2 2011-06-23 01:22:08

roygbiv
Member
Registered: 2011-05-18
Posts: 204

Re: How to set the title of an urxvt window?

indianahorst wrote:
case $TERM in
   xterm*|*rxvt*|Eterm|eterm|rxvt-unicode|urxvt)
      PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
      ;;
   screen)
      PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
      ;;
esac 

It is possible to override the .bashrc with the -title option if you simply don't have an entry in the case there for your specified terminal (in this case urxvt). The reason why it doesn't work the other way is because .bashrc is sourced by bash, which is started by the terminal in the first place. So when using the -title option, the terminal title is first set by urxvt, but then bash sources the .bashrc and the title is overridden.

By the way, I don't think you need 'rxvt-unicode' and 'urxvt' in your cases because *rxvt* covers both. Also have a check in your global /etc/bash.bashrc file for terminal stuff.

Offline

#3 2011-06-23 02:58:02

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: How to set the title of an urxvt window?

I would recommend that you not use the PROMPT_COMMAND to set your bash prompt at all.  Use the PS1 environment variable. By using PROMPT_COMMAND, you are invoking a subshell each time you hit return; which is most likely unnecessary.

In fact, you are probably already setting PS1 in your .bashrc; and that is what is changing your window title.  You can set PS1 to a different value, and then it will not reset your window title with each command.

Just set PS1 in your .bashrc to:

PS1="[\u@\h \W]\$ "

You can see a more complete list of the available \u, \H, etc. options here.

If you do wish to reset the urxvt window title by setting PS1, do the following:

PS1="[\u@\h \W]\$ "
PS1="\[\e]2;\u \W\a\]$PS1"

Edit:  As I look at this a little closer, I see that your PROMPT_COMMAND is indeed setting your window title.  You could change it to the following:

PROMPT_COMMAND='echo -ne "${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}"'

But I would still not use PROMPT_COMMAND and just set PS1 instead.

Last edited by rockin turtle (2011-06-23 03:53:57)

Offline

Board footer

Powered by FluxBB