Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change gnome-terminal title to reflect the current directory?

I want to change the title of the gnome-terminal window to reflect the current directory. Is there a way to do that? A script may be? The "change terminal title" threads did not help much. Manually when we use the command:

gnome-terminal --title=$PWD  

it works, but a new terminal instance is created (as expected). I want to be able to use the

--title=$PWD  

with the cd command.

Is there a way to achieve that?

like image 501
okkhoy Avatar asked May 09 '12 13:05

okkhoy


2 Answers

since gnome-terminal uses the same control commands as xterm this page might be helpful.

Xterm Title for bash and other shells

TL;DR:

add following to your .bashrc

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

like image 132
dwalter Avatar answered Sep 19 '22 22:09

dwalter


PROMPT_COMMAND='echo -ne "\033]0;$(basename ${PWD})\007"' will display only the current directory as the title

like image 31
user2909452 Avatar answered Sep 19 '22 22:09

user2909452