Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sporky023/f2dd5fb98cd9d300af122e474e6fd806 to your computer and use it in GitHub Desktop.
Save Sporky023/f2dd5fb98cd9d300af122e474e6fd806 to your computer and use it in GitHub Desktop.
bash / PS1 / display two levels of pwd context
# thanks: https://muffinresearch.co.uk/showing-last-two-directories-of-pwd-in-bash-prompt/
function PWD {
pwd | sed 's/^\/Users\/<YOUR_USERNAME>/~/' | awk -F\/ '{print $(NF-1),$(NF)}' | sed 's/ /\//' | sed 's/~\/~/~/'
}
export PS1="\u\[\e[m\]:\[\e[36m\]\$(PWD)\[\e[m\] "
# backslash before $ tells it to run the function each time;
# else it is only run once and won't update as you switch directories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment