git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] bash completion: add space between branch name and status flags

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 30, 2009, 19:27 UTC
Message-ID
<7veimc1cv6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20091230145751.GE6914@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 11 quoted lines
> Nanako Shiraishi <nanako3@lavabit.com> wrote:
>> Junio, could you tell us what happened to this thread?
>> 
>> In response to a patch from Roman Fietze to outline a better way
>> to do it.  Nothing happened.
>
> Junio responded with a suggestion on how to improve the patch when
> GIT_PS1_SHOWDIRTYSTATE was not set, but Roman Fietze didn't send
> a revised patch, so it got dropped.
>
> Here is the revised patch, Junio, still think its a good idea?
Thanks for following up.

As I don't use $[wisu] myself, I don't have a very strong opinion either way, but the user has spent cycles to compute them, so we'd better present them in a way that is easier to read, I guess.

Show 17 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index fbfa5f2..3c8b6df 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -163,10 +163,12 @@ __git_ps1 ()
>  			fi
>  		fi
>  
> +		local f="$w$i$s$u"
> +		f="${f:+ $f}$r"
>  		if [ -n "${1-}" ]; then
> -			printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
> +			printf "$1" "$c${b##refs/heads/}$f"
>  		else
> -			printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
> +			printf " (%s)" "$c${b##refs/heads/}$f"
>  		fi

I notice that printf argument look very similar. Maybe we want to do something like

    printf "${1:-" (%s)"}" ...
to avoid duplication?
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 5 of 7 in “bash completion: add space between branch name and status flags”
  1. bash completion: add space between branch name and status flagsRoman Fietze, Nov 20, 2009
  2. Junio C HamanoNov 20, 2009
  3. Nanako ShiraishiDec 30, 2009
  4. Shawn O. PearceDec 30, 2009
  5. Junio C HamanoDec 30, 2009
  6. bash completion: add space between branch name and status flagsShawn O. Pearce, Dec 31, 2009
  7. Roman FietzeJan 6, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.