Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Shortened bit branch in prompt
- X-seq: zsh-users 26490
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Shortened bit branch in prompt
- Date: Wed, 10 Feb 2021 12:45:13 +0000 (GMT)
- Archived-at: <https://zsh.org/users/26490>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/1216298849.3722151.1612961113500%40mail2.virginmedia.com>
- Importance: Medium
- In-reply-to: <20210210120501.GA3727@gmx.de>
- List-id: <zsh-users.zsh.org>
- References: <20210210120501.GA3727@gmx.de>
> On 10 February 2021 at 12:05 Dominik Vogt <dominik.vogt@xxxxxx> wrote:
> I want to change that so
>
> * If the branch name is max. 25 characters, print it umodified.
> * If the branch ame is loger, print
>
> <first 17 characters>...<last five characters>
>
> E.g. if the branch name is abcdefghijklmnopqrstuvwxyz0123456789,
> the prompt should have
>
> abcdefghijklmnopq...56789
>
> Of course this should be done with zsh functionality only.
It's possible to be completely general about printing a variable substitution
based on the length, in this case of variable "foo":
print ${${${${${:-$(( ${#foo} > 25 ))}##1}:-Printed if long}##0}:-Printed if short}
Those arbitrary chunks are subject to further expansion, so put the expressions
you need there --- in particular, $foo, ${foo[1.17]}...${foo[-5,-1]}, I haven't
put those in myself just for the sake of clarity of what's going on.
There are probably ways of shortening this, but by the standards of the squiggle
factory that's arguably quite readable. (Only arguably.)
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author