Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Shortened bit branch in prompt
- X-seq: zsh-users 26489
- From: Dominik Vogt <dominik.vogt@xxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Shortened bit branch in prompt
- Date: Wed, 10 Feb 2021 13:05:01 +0100
- Archived-at: <https://zsh.org/users/26489>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/20210210120501.GA3727%40gmx.de>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Zsh Users <zsh-users@xxxxxxx>
- Reply-to: dominik.vogt@xxxxxx
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author