Why do you want to do it without modifying your PS1 variable? That is the correct way to do it.
If you run the following, you'll get what you want:
export PS1="\[\e]0;\W\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
This is just taking the default prompt:
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
... and replacing \u@\h: \w
with \W
.
You can do the same thing with any command that echoes the right escape code:
echo -en "\e]0;${PWD##*/}\a"
... but then you'd be constantly fighting bash to stop it from doing it using PS1 (the best way).
Best Answer
A lot of programs will overwrite the title so you can't rely on the title being fixed or not duplicated by other windows. This is especially so with remote ssh sessions in a gnome-terminal. It still helps a lot but its not reliable enough for window managers to do matching against (which is why I think they removed it. (addition by Amias Channer)) so this ability has been taken out with the newest
gnome-terminal
, however there is still a possibility to change the title, you can do it by command. To achieve this easily edit your~/.bashrc
file and add the following lines:With this you then can set the title of your terminal window by simply using the command
set-title <name you want to set it to>
. This is possible due to ANSI escape codes so any program can output them regardless of where the code is run. That's what the \e and \a bits do. (addition by Amias Channer).The solution I found here and using it myself since I run on 16.04 LTS.