Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Shortened bit branch in prompt



On Wed, Feb 10, 2021 at 4:05 AM Dominik Vogt <dominik.vogt@xxxxxx> wrote:
>
>  * If the branch name is max. 25 characters, print it umodified.
>  * If the branch ame is loger, print
>
>      <first 17 characters>...<last five characters>

Could you do this using the %> and %< prompt expansion escapes?

x=abcdefghijklmnopqrstuvwxyz0123456789
print -r -- ${(%):-%20>...>$x%>>%5<<$x%<<}

That still needs a conditional to determine (( $#x > 25 )).  Perhaps then:

setopt extendedglob
pat="(${(l:20::?:):-})?*(${(l:5::?:):-})"
print -r -- ${x/(#b)${~pat}/${match[1]}...${match[2]}}

I don't recall whether ${(*)...} to temporarily turn on extended
globbing is very common in the wild, yet.




Messages sorted by: Reverse Date, Date, Thread, Author