zsh-users
 help / color / mirror / code / Atom feed
* Shortened bit branch in prompt
@ 2021-02-10 12:05 Dominik Vogt
  2021-02-10 12:45 ` Peter Stephenson
  2021-02-11  1:43 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Dominik Vogt @ 2021-02-10 12:05 UTC (permalink / raw)
  To: Zsh Users

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-11  1:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 12:05 Shortened bit branch in prompt Dominik Vogt
2021-02-10 12:45 ` Peter Stephenson
2021-02-10 15:40   ` Dominik Vogt
2021-02-11  1:43 ` Bart Schaefer

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).