RHEL: Don’t use full path for terminal title and set title for Vim

By default the terminal title in RHEL displays the full path of the current working directory. If you’re working in a nested directory this makes the terminal or tab title very long. For example, the terminal or tab title could be /etc/systemd/network . If you’re using a terminal with tabs and have a lot of tabs open, this long tab title will consume a lot of space on the tab bar.

Instead of using the full path it’s better to have the terminal or tab title set to the current directory name only or what is called the ‘short path’ or ‘basename’.

Also, the default Bash prompt in RHEL puts square brackets around the prompt which are unnecessary and waste space.

To fix the terminal title and Bash prompt create the file /etc/profile.d/prompt-customization.sh with the following contents:

PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="\u@\h \W\\$ "

If you prefer to display the full path in the prompt change \W in the second line to \w

If you use the Vim editor you may want to have the terminal/tab title set to the name of the file being edited. Create /etc/vimrc.local with the following contents:

set title
augroup WindowTitleGroup
  autocmd!
  autocmd BufEnter,BufFilePost * let &titlestring = expand('%:t')
augroup end