Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Shortened bit branch in prompt
- X-seq: zsh-users 26504
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: dominik.vogt@xxxxxx, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Shortened bit branch in prompt
- Date: Wed, 10 Feb 2021 17:43:08 -0800
- Archived-at: <https://zsh.org/users/26504>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/CAH%2Bw%3D7aKskZrDo8hFk8AM-FUWHBtgtkwQnbeCtnKv%2BsZyeFa%3Dw%40mail.gmail.com>
- In-reply-to: <20210210120501.GA3727@gmx.de>
- List-id: <zsh-users.zsh.org>
- References: <20210210120501.GA3727@gmx.de>
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