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?
Asked
Active
Viewed 6,625 times
5

dessert
- 39,982

asdfkjasdfjk
- 381
1 Answers
6
Open your ~/.bashrc
in your preferred text editor and search the PS1
line, by default it says
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
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
:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
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
Use \w
instead of \W
for the full cwd path.
Related questions

dessert
- 39,982
blue
marked directory names to show only last directory name. Your above solutions successfully change the title but it would be nice if I can change the blue marked name as well. – asdfkjasdfjk Aug 10 '19 at 16:22