Currently, this is the format of my ZSH Prompt. I have been reading over https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Prompt-Expansion to further understand truncation in zsh prompts, but I cannot figure out how to solve this nested truncation problem I am running into.

export PROMPT="(%10>,,,>[%5>...>william%>>]hello%>>)"



when I want it to initially truncate the interior expression %5>...>william%>> then take that truncated expression and pass it into the exteriior expression and truncate that.

i.e. I want the output


1 Answer 1


The manual says that

The part of the prompt string to be truncated runs to the end of the string, or to the end of the next enclosing group of the %( construct, or to the next truncation encountered at the same grouping level (i.e. truncations inside a %( are separate), which ever comes first. In particular, a truncation with argument zero (e.g., %<<) marks the end of the range of the string to be truncated while turning off truncation from there on.

That is, they don't nest on the same level: the first %>> stops truncation and the second does nothing since truncation isn't active any more there.

But you can nest them with %(...).

PROMPT='%12>#>12[%(0l,%5>#>abcefghijk,)]345678%>> end$ '


12[abce#]34# end$

The inner part is abcefghijk, it's truncated to five characters, and wrapped in [], and then the 12[abce#]345678 gets truncated to 12 characters.


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.