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

Re: Where should git-prompt.sh be installed?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 25, 2012, 16:12 UTC
Message-ID
<20121025161250.GA30334@elie.Belkin>
In-Reply-To
<20121025151120.GA14740@goldbirke>
SZEDER Gábor wrote:
> On Wed, Oct 24, 2012 at 05:51:06PM -0700, Jonathan Nieder wrote:
Show 7 quoted lines
>> Proposal:
>>
>>   1) /usr/lib/git-core/git-sh-prompt
>>   2) git-sh-prompt(1)
>
> Not sure about the "sh" part.  The prompt function is very
> Bash-specific, it won't work under a plain POSIX shell.
That's an interesting point.  Here's my logic:

The prompt function was originally Bash-specific, but over time it gained support for Zsh as well. If we're lucky, some day it might gain support for mksh.

Meanwhile something simple like "git-prompt" would sound too much like a normal git command, I fear.

Shell language extensions used:
 * future standard: local variables
 * cosmetic: [[ and (( syntax in place of test and $(
 * cosmetic: for ((n=1; n <= n_stop; n++)) instead of a more explicit
   while loop
 * cosmetic: var+=value syntax
 * optimization: <<< syntax to iterate over lines in a variable
   instead of, for example, sed + eval
 * arrays: svn_remote, svn_upstream --- using plain variables would
   require some escaping.

So nothing fundamental, but since this is only useful in shells like Bash that support command substitution in $PS1, it seems reasonable to keep using the extensions until someone wants to use it with a more limited shell.

In other words, the interface is still "this is a scriptlet you might source in your Bourne-style shell to get a __git_ps1 function to use in your prompt". The implementation language just happens not to be POSIX shell today.

Perhaps it should return early in shells other than bash and zsh to help people keep their .shrc simple. What do you think?

> Do other VCSes have similar prompt scripts?  Where do they install
> theirs?

Mercurial has an hg-prompt extension that can be used by running "hg prompt". http://mercurial.selenic.com/wiki/PromptExtension

I haven't found one for Subversion.
Bazaar has contrib/bash/bzrbashprompt.sh.  It doesn't get installed.

Thanks, Jonathan

Previous: SZEDER GáborNext: Junio C Hamano
Message 29 of 34 in “completion: split into git-prompt.sh”
  1. 0/2 completion: split into git-prompt.shFelipe Contreras, May 22, 2012
  2. 1/2 completion: remove executable modeFelipe Contreras, May 22, 2012
  3. 2/2 completion: split __git_ps1 into a separate scriptFelipe Contreras, May 22, 2012
  4. Zbigniew Jędrzejewski-SzmekMay 22, 2012
  5. Ted PavlicMay 22, 2012
  6. Felipe ContrerasMay 23, 2012
  7. Felipe ContrerasMay 23, 2012
  8. Junio C HamanoMay 23, 2012
  9. Felipe ContrerasMay 23, 2012
  10. Junio C HamanoMay 23, 2012
  11. Ted PavlicMay 23, 2012
  12. Felipe ContrerasMay 23, 2012
  13. Ted PavlicMay 23, 2012
  14. SZEDER GáborMay 24, 2012
  15. SZEDER GáborMay 24, 2012
  16. Ted PavlicMay 22, 2012
  17. Felipe ContrerasMay 23, 2012
  18. Junio C HamanoMay 23, 2012
  19. SZEDER GáborMay 24, 2012
  20. Ville SkyttäMay 25, 2012
  21. Where should git-prompt.sh be installed?Jonathan Nieder, Oct 25, 2012
  22. Drew NorthupOct 25, 2012
  23. Danny YatesOct 25, 2012
  24. __git_ps1: migrate out of contrib/completionJonathan Nieder, Oct 25, 2012
  25. Felipe ContrerasOct 25, 2012
  26. Todd ZullingerNov 8, 2012
  27. Anders KaseorgOct 25, 2012
  28. SZEDER GáborOct 25, 2012
  29. Jonathan NiederOct 25, 2012
  30. Junio C HamanoMay 23, 2012
  31. SZEDER GáborMay 25, 2012
  32. Thomas RastMay 25, 2012
  33. Felipe ContrerasMay 25, 2012
  34. Junio C HamanoMay 25, 2012

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.