zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: dominik.vogt@gmx.de, Zsh Users <zsh-users@zsh.org>
Subject: Re: Shortened bit branch in prompt
Date: Wed, 10 Feb 2021 17:43:08 -0800	[thread overview]
Message-ID: <CAH+w=7aKskZrDo8hFk8AM-FUWHBtgtkwQnbeCtnKv+sZyeFa=w@mail.gmail.com> (raw)
In-Reply-To: <20210210120501.GA3727@gmx.de>

On Wed, Feb 10, 2021 at 4:05 AM Dominik Vogt <dominik.vogt@gmx.de> 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.


      parent reply	other threads:[~2021-02-11  1:44 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
2021-02-10 15:40   ` Dominik Vogt
2021-02-11  1:43 ` Bart Schaefer [this message]

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='CAH+w=7aKskZrDo8hFk8AM-FUWHBtgtkwQnbeCtnKv+sZyeFa=w@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=dominik.vogt@gmx.de \
    --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).