How to change the terminal title and the prompt path to show only the current working directory’s name? [duplicate]
772
I use Terminator terminal. As you can see from the screenshot below, everywhere it shows the directory names. Instead of showing whole directory names, I want it to show only the last directory name i.e ecommerce in this case. Is there a way to do this?
To change your prompt, i.e. the coloured part in front of every command line, to show only the current working directory’s name instead of its path, change \w to \W:
To set the terminal’s (or terminal tab’s) title to the cwd you need to append \[\e]2;\W\a\] to this line, this can be done e.g. at the end directly before the closing ' or – because the line is long enough – on a separate line directly afterwards:
PS1=$PS1'\[\e]2;\W\a\]' # set terminal title to cwd
Open your
~/.bashrc
in your preferred text editor and search thePS1
line, by default it saysTo change your prompt, i.e. the coloured part in front of every command line, to show only the current working directory’s name instead of its path, change
\w
to\W
:To set the terminal’s (or terminal tab’s) title to the cwd you need to append
\[\e]2;\W\a\]
to this line, this can be done e.g. at the end directly before the closing'
or – because the line is long enough – on a separate line directly afterwards:Use
\w
instead of\W
for the full cwd path.Related questions