Only showing the last 2 directories in the terminal prompt?

I'm just going to throw this out there for the few ksh users on the Mac besides myself. I did not create this, I just use it.

# Discipline function for relative present working directory
# by Martijn Dekker <[email protected]> 2020-08-09; public domain
function _relative_pwd.get
{
    typeset del ellip=$'\u2026' v=$PWD keep=*/*   # add /* for each element to keep
    ((${#ellip}==1)) || ellip='...'
    [[ ($v == "$HOME" || $v == "$HOME"/*) && $HOME != / ]] && v=\~${v#"$HOME"}                                          
    del=${v%/$keep}/
    [[ $v == /*/$keep ]] && v=$ellip/${v#"$del"}
    [[ $v == \~/*/$keep ]] && v=\~/$ellip/${v#"$del"}
    .sh.value=$v
}

And set PS1

$ PS1="\${_relative_pwd} $ "

Example resulting prompt...

~/…/ksh/arch $


Per the Unix StackExchange Link, this will do the trick (I'm using a bash shell):

vi ~/.bash_profile`

And add

export PS1='${PWD#"${PWD%/*/*}/"} \$ '

Then save and source ~/.bash_profile.