2

Can zsh set the prompt to the whole path except the current dir? I.e. for ~/a/b/c/ to just ~/a/b/?

I'm trying to get this result for ~/a/b/c with left & right prompts:

c/: | ~/a/b/

as opposed to my current duplicated c:

c/: | ~/a/b/c/

The duplication wastes space if the c dir name is long.

In the manual I found everything else than what i want:

  • %-1~ - the first element of the path
  • %1~ - the last element of the path

instead of all except the last

How can it be done?

1 Answer 1

2
# Before printing each prompt string, apply substitutions to it.
setopt promptsubst

# $PWD is always equal to the present working dir.
# :h chops off the last item of the path.
# (D) substitutes the start of the path with a named dir, such as ~, if possible.
# Note that this string is in 'single quotes'!
RPS1='${(D)PWD:h}'

Ta-da!

Documentation:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .