My current command prompt displays the entire path from my home directory to my cwd. For instance a possible command prompt would be ~/Desktop/images/japan λ. How do I make it such that it always shows only the most precise location in my cwd. For example the previous command prompt would instead be japan λ or ~/japan λ.

My current zshrc file which implements my command prompt contains:

PS1='%F{cyan}%~ %B%F{yellow}λ%f%b '
PS2='%B%F{yellow}⤷%f%b '

Looking at http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html it shows that you can do this by giving the %~ prompt expansion in PS1 an integer right after the percentage sign.

PS1='%F{cyan}%1~ %B%F{yellow}λ%f%b '

The 1 after the percent will get you what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.