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

Re: [PATCH 1/6] prompt: don't scream continuation state

From
Jeff King <peff@peff.net>
Date
Jun 3, 2013, 21:15 UTC
Message-ID
<20130603211556.GB23224@sigill.intra.peff.net>
In-Reply-To
<CALkWK0=LzUe0k7rWcrbiiTZNOOGg+=SsQB3u2F2ysjb5AJ=qZw@mail.gmail.com>
On Mon, Jun 03, 2013 at 03:17:27PM +0530, Ramkumar Ramachandra wrote:
Show 22 quoted lines
> Thomas Rast wrote:
> > Do you have other ways of distinguishing the branch and the state?
> > Colors?  I'm a bit too lazy to check.  Perhaps it could be made to only
> > use caps if not in colored mode?
> 
> Currently, no.   See git-prompt.sh:401, 403, 409; we don't have a
> separate color for $r.  I didn't introduce a color in this series
> because it would conflict with rr/zsh-color-prompt which is in pu: we
> can introduce it after that graduates.  I was thinking yellow, since
> that's not taken?
> 
> You really should use colors.  I don't think it's worth the extra
> ugliness to scream in the no-color case.
> 
> As such, the prompt is a fine bikeshedding target.  I even introduced
> GIT_PS1_SEPARATOR, because some people were unhappy with me stripping
> one whitespace (yes, one).  If we go down the configurability road,
> we'll either end up with a ton of environment variables, or be made to
> write a generalized custom formatter which splices together tons of
> arguments using color (super painful).  While I do agree that it is a
> matter of taste, we have to make a few compromises for the sake of
> sanity.

It seems silly to argue about output formats when we are writing a prompt in a convenient Turing-complete scripting language already. What about something like:

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index eaf5c36..1da3833 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -404,6 +404,8 @@ __git_ps1 ()
 			fi
 			gitstring=$(printf -- "$printf_format" "$gitstring")
 			PS1="$ps1pc_start$gitstring$ps1pc_end"
+		elif test "$(type -t __git_ps1_printer)" = "function"; then
+			__git_ps1_printer
 		else
 			# NO color option unless in PROMPT_COMMAND mode
 			printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"

and then you can define your own custom function if you like, which will
inherit all of the variables from __git_ps1. E.g.:

  __git_ps1_printer() {
          echo "${r,,}"
  }

yields a lower-case "rebase-i". Of course there are many other variables
you want to put in your prompt, too. The only problem I see is that the
current set of variables is not suitable as a user-visible interface.
The names are not good (the branch should be "$branch" rather than "$b",
the operation-in-progress should be "$operation" or similar rather than
"$r", etc), and the formats are not as convenient ("$r" contains the
full "|REBASE-i 6/10", whereas it should be broken down so the printing
function can easily use a case statement).

And of course the variables would need documentation.

-Peff
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 5 of 33 in “Minor prompt, completion cleanups”
  1. 0/6 Minor prompt, completion cleanupsRamkumar Ramachandra, Jun 2, 2013
  2. 1/6 prompt: don't scream continuation stateRamkumar Ramachandra, Jun 2, 2013
  3. Thomas RastJun 3, 2013
  4. Ramkumar RamachandraJun 3, 2013
  5. Jeff KingJun 3, 2013
  6. Ramkumar RamachandraJun 4, 2013
  7. Jeff KingJun 4, 2013
  8. Junio C HamanoJun 4, 2013
  9. Junio C HamanoJun 3, 2013
  10. 2/6 completion: add common options for rev-parseRamkumar Ramachandra, Jun 2, 2013
  11. Ramkumar RamachandraJun 7, 2013
  12. 3/6 completion: add common options for blameRamkumar Ramachandra, Jun 2, 2013
  13. Thomas RastJun 3, 2013
  14. Ramkumar RamachandraJun 3, 2013
  15. SZEDER GáborJun 3, 2013
  16. Junio C HamanoJun 3, 2013
  17. Peter KreftingJun 6, 2013
  18. Junio C HamanoJun 3, 2013
  19. 4/6 completion: correct completion for format-patchRamkumar Ramachandra, Jun 2, 2013
  20. Felipe ContrerasJun 2, 2013
  21. Ramkumar RamachandraJun 2, 2013
  22. 5/6 completion: clarify difftool completionRamkumar Ramachandra, Jun 2, 2013
  23. Junio C HamanoJun 3, 2013
  24. 6/6 completion: clarify ls-tree, archive, show completionRamkumar Ramachandra, Jun 2, 2013
  25. Junio C HamanoJun 3, 2013
  26. Ramkumar RamachandraJun 4, 2013
  27. Junio C HamanoJun 4, 2013
  28. Junio C HamanoJun 3, 2013
  29. SZEDER GáborJun 3, 2013
  30. Ramkumar RamachandraJun 7, 2013
  31. Junio C HamanoJun 7, 2013
  32. SZEDER GáborJun 7, 2013
  33. Junio C HamanoJun 9, 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.