And if you want to get really hairy and avoid applications that aren't installed by default:
xkill -id `xprop -root _NET_ACTIVE_WINDOW | cut -d\# -f2`
Again, this seems to work fairly well.
NOTE: In the case of some applications (see comments) this may mean that all windows for an application are closed. gnome-terminal
is one such application but terminator
and xterm
are not affected. I would suggest this is more a bug (maybe by design) with those applications rather than one with my command.
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:

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:

Best Answer
The following will set the terminal's title to "New terminal title":
You will probably also have to change the environment variable PS1, first though, otherwise your changes won't show up because it will reset the title after each command. The default .bashrc that ships with Ubuntu contains the following line:
... the "\e]0;" code tells it to write everything up to the "\a" in both the title and icon-name properties. You need to remove that and set it to something like this (i.e. without the \e]0; code):
Then any changes that you make with the above echo command will change the terminal title. If you're going to use this a lot, you can throw it into a function in your ~/.bashrc file:
Then you can just set the title to "kittens" from the command line by doing:
(You have to restart bash though after editing .bashrc, for your changes to take effect)