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

Re: [PATCH] bash prompt: add option to disable for a repository

From
Johannes Sixt <j6t@kdbg.org>
Date
Nov 23, 2013, 14:42 UTC
Message-ID
<5290BEE7.2070901@kdbg.org>
In-Reply-To
<1385212703-9611-1-git-send-email-hoxu@users.sf.net>
Am 23.11.2013 14:18, schrieb Heikki Hokkanen:
Show 37 quoted lines
> If bash.prompt is set to false, disable the prompt. This is useful
> for huge repositories like the home directory.
> 
> Signed-off-by: Heikki Hokkanen <hoxu@users.sf.net>
> ---
> git-prompt.sh performance seems to be quite bad for big repositories, so
> without a way to disable it selectively for repositories, it becomes unusable
> for people who have their homedir under git. This patch generalizes the problem
> a bit by allowing the prompt to be disabled by setting bash.prompt to false in
> any repository.
> 
>  contrib/completion/git-prompt.sh | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 7b732d2..c982fde 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -84,6 +84,8 @@
>  # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
>  # the colored output of "git status -sb" and are available only when
>  # using __git_ps1 for PROMPT_COMMAND or precmd.
> +#
> +# To disable prompt for a repository, run "git config bash.prompt false"
>  
>  # check whether printf supports -v
>  __git_printf_supports_v=
> @@ -304,6 +306,12 @@ __git_ps1 ()
>  		return
>  	fi
>  
> +	local prompt_setting
> +	prompt_setting=$(git config --bool bash.prompt)
> +	if [ -n "$prompt_setting" ] && [ "$prompt_setting" == "false" ]; then
> +		return
> +	fi
> +

Gah! This adds a fork+exec each time the prompt is shown. Not good, particularly on Windows.

Since your intent is to disable the prompt in the home directory, wouldn't that mean that most of the time you *don't* want the prompt? Wouldn't you be better served with a method that *turns on* the prompt? For example, a shell function that sets PS1 and another one that unsets it? Or a wrapper that inspects a shell variable and calls __git_ps1 only when you want a prompt.

>  	local short_sha
>  	if [ "$rev_parse_exit_code" = "0" ]; then
>  		short_sha="${repo_info##*$'\n'}"
> 
-- Hannes
Previous: Heikki HokkanenNext: Heikki Hokkanen
Message 2 of 9 in “bash prompt: add option to disable for a repository”
  1. bash prompt: add option to disable for a repositoryHeikki Hokkanen, Nov 23, 2013
  2. Johannes SixtNov 23, 2013
  3. Heikki HokkanenNov 23, 2013
  4. Jonathan NiederNov 25, 2013
  5. SZEDER GáborNov 26, 2013
  6. Johannes SixtNov 26, 2013
  7. Thomas RastNov 26, 2013
  8. SZEDER GáborNov 23, 2013
  9. Heikki HokkanenNov 25, 2013

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.