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
Nov 20, 2009, 17:53 UTC
Message-ID
<7v4oopxeuf.fsf@alter.siamese.dyndns.org>
In-Reply-To
<200911201309.16193.roman.fietze@telemotive.de>
Roman Fietze <roman.fietze@telemotive.de> writes:
Show 5 quoted lines
> Hello Shawn, hello git list members,
>
> Wouldn't it improve the readability of the bash prompt, if there would
> be a space between the branch name and the status flags (dirty, stash,
> untracked)?
Perhaps.
Show 15 quoted lines
> Signed-off-by: Roman Fietze <roman.fietze@telemotive.de>
> ---
>  contrib/completion/git-completion.bash |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-
> completion.bash
> index bd66639..407176b 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -169,10 +169,12 @@ __git_ps1 ()
>  			fi
>  		fi
>  
> +		local f="$w$i$s$u$r"

I think this line and the two changes to printf below is a big improvement (unless we are using f for something else---I didn't look). But I think the next line is wrong.

> +		f=${f:+ $f}

The $r string is designed to be used as suffix from the beginning and always has "|" in front of it as a delimiter, so if there is no w/i/s/u (and I suspect many people do not use GIT_PS1_SHOWDIRTYSTATE and friends, and these are _always_ empty for them) the above will begin with "|". There is no need to steal one column from a typeable width from the command line in such a case.

Show 9 quoted lines
>  		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
>  	fi
>  }

To implement your stated goal (dirty/stash/untracked), you probably want to do this instead...

	local f="$w$i$s$u"
        f="${f:+ $f}$r"
Previous: Roman FietzeNext: Nanako Shiraishi
Message 2 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.