\W (capital W) instead of
\w (lowercase) in your
PS1 string. e.g.
PS1='[\u@\h \W] '
\w the current working directory, with $HOME abbreviated with a tilde (uses the value of the
\W the basename of the current working directory, with
$HOME abbreviated with a tilde
bash, you can also set the
If set to a number greater than zero, the value is used as the
number of trailing directory components to retain when expanding
\W prompt string escapes (see PROMPTING below).
Characters removed are replaced with an ellipsis.
If you want the prompt to always display the directory two levels above the current directory (or something similarly complicated or unusual), you will need to use command substitution inside the PS1 string.
Note that the PS1 string has to be enclosed in single-quotes, not double-quotes - otherwise you'll get the return value of the command-subst at the time PS1 was defined, rather than it being re-evaluated every time the prompt is displayed.
PS1='[\u@\h $(basename $(realpath ../../))] '