7

I've selected "Replace initial title" setting in gnome-terminal's preferences, but it just shows the default title "Terminal". After reading this answer, I added this to my .bashrc:

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'

and also commented out this line:

#PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

After restarting terminal, it started to show user@hostname: ~/currentdir in its title, changing it whenever I cd to another directory. But it still does not change when I launch CLI programs like cmus and vim (vim, for example, sets current filename as a title).

I've installed rxvt and everything works fine there.

Ubuntu 13.04, gnome-terminal 3.6.1.

My .bashrc - almost the same as shipped with default ubuntu installation.

Screenshot of terminal

galymzhan
  • 123

3 Answers3

2

First, you have something contradictory in your question. You said, "it started to show user@hostname: ~/currentdir in its title, changing it whenever I cd to another directory", but the image attached said something else. I am almost sure that if you've selected "Replace initial title" setting in gnome-terminal's preferences and if you use this ~/.bashrc file as you said, your terminal should look like in the following image:

galymzhan@atom

Second, you're totally wrong with: "vim, for example, sets current filename as a title". To do this, you must to heve a file named .vimrc in your home directory with the following code inside:

let &titlestring = $USER . "@" . hostname() . ": vim " . expand("%:t")
if &term == "screen"
  set t_ts=^[k
  set t_fs=^[\
endif
if &term == "screen" || &term == "xterm"
  set title
endif

And one more thing: I don't understand yet exactly for what do you using that if from the 11th line until 40th line in your .bashrc file, but setting up TERM="gnome-256color" at the line 33 may be a problem in this case. So, I suggest you to comment that line, or to remove all the code between lines 11 and 40.

After all of this done, when you will use vim, your terminal should look like:

galymzhan@atom: vim

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
0

Just to be certain, when you edited the default profile, did you try to save that configuration? Shut the terminal, and then re-opened it? Did it fail?

The normal, out-of-the-box install does replace the initial title in my experience, so I am a little surprised by the issue.

Try this method:

  1. Open a terminal
  2. on the tollbar at the top of the screen click on Edit > Profiles
  3. Select the Default profile
  4. Click on the 'Edit' button with the Default profile highlighted
  5. Click on 'Title and Command' Tab
  6. Insure that the 'Replace Initial Title' button is visible
  7. Click the 'Close" button on each screen to go back to the terminal
  8. Exit the terminal
  9. Restart a terminal session

You should have the title automatically replaced with your unique username and path in your home directory.

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
freecode
  • 695
0

Here's what works for me:

  1. Install the xttitle package.
    sudo apt-get install xttitle
  2. Add to ~/.bashrc:
    PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[1;31m\]($?)\[\033[00m\]\$ '

  3. Add to .bashrc

    # from the "xttitle(1)" man page - put info in window title  
    update_title()   {  
      [ $TERM = xterm -o $TERM = xterm-color ] && xttitle "[$$] ${USER}@${HOSTNAME}:$PWD"
    }  
    cd()
    {  
      builtin cd "${@}"
      update_title
    }
    
waltinator
  • 37,856