zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Shortened bit branch in prompt
Date: Wed, 10 Feb 2021 12:45:13 +0000 (GMT)	[thread overview]
Message-ID: <1216298849.3722151.1612961113500@mail2.virginmedia.com> (raw)
In-Reply-To: <20210210120501.GA3727@gmx.de>

> On 10 February 2021 at 12:05 Dominik Vogt <dominik.vogt@gmx.de> 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


  reply	other threads:[~2021-02-10 12:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 12:05 Dominik Vogt
2021-02-10 12:45 ` Peter Stephenson [this message]
2021-02-10 15:40   ` Dominik Vogt
2021-02-11  1:43 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1216298849.3722151.1612961113500@mail2.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).