Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Shortened bit branch in prompt



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