zsh-users
 help / color / mirror / code / Atom feed
From: Dominik Vogt <dominik.vogt@gmx.de>
To: Zsh Users <zsh-users@zsh.org>
Subject: Shortened bit branch in prompt
Date: Wed, 10 Feb 2021 13:05:01 +0100	[thread overview]
Message-ID: <20210210120501.GA3727@gmx.de> (raw)

I have this function to put the name of the current git branch in
the shell prompt if the working directory is inside a git tree:

--
__git_ps1 () {
	local b="$(
		git symbolic-ref -q HEAD 2> /dev/null ||
		{ [[ $? == 1 ]] && printf '*none*'} )"
	if [[ -n "$b" ]]
	then
		printf " (%s)" "${${b##refs/heads/}:0:25}"  <---------------
	fi
}
--

Since a customer uses absurdly long branch names, it uses only the
first 25 characters of the name.

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.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 12:05 Dominik Vogt [this message]
2021-02-10 12:45 ` Peter Stephenson
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=20210210120501.GA3727@gmx.de \
    --to=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).