How to get absolute path on a zsh prompt?

To preserve original prompt format (colors, git info and potentially other customisations before this one) except related to path info, you could append following to the end of ~/.zshrc:

PROMPT=${PROMPT/\%c/\%~}

As pointed out by @caleb-adams and @fend25 the key is replacing %c (just folder name) with %~ to include full path (or absolute from $HOME when under ~). See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html for more info


Simplest way to add bash-style dir path to the prompt. Just add this to ~/.zshrc:

setopt PROMPT_SUBST
PROMPT='%n@%m: ${(%):-%~} '

The part with the path is ${(%):-%~}. Colouring could be added according with your lifestyle:)


As Horacio Chavez mentioned in the comment above, you want to look here: http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html for the details on how to change your displayed path in zsh.

In this case if you are looking for a path that is relative to your home folder, include a %~ in your zsh-theme file. Your prompt would now look like this:

PS1='${SSH_CONNECTION+"%{$fg_bold[green]%}%n@%m:"}%{$fg_bold[green]%}Location: %~%{$reset_color%}$(git_prompt_info) '

note, I only changed one character in your prompt. the %c was swapped for the %~. %c will only give your current directory (see the document link above, or here)

For a full path you could use %/

Tags:

Zsh