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

Re: [PATCH 0/8] git-prompt: support more shells

From
avih <avihpit@yahoo.com>
Date
Jul 24, 2024, 17:08 UTC
Message-ID
<2104161937.2499137.1721840883913@mail.yahoo.com>
In-Reply-To
<xmqq7cdazu4a.fsf@gitster.g>
 On Wednesday, July 24, 2024 at 06:29:12 PM GMT+3, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
>
> It is a bit more nuanced than that, though.  Here is what we say:
>
> - Even though "local" is not part of POSIX, we make heavy use of it
>   in our test suite.  We do not use it in scripted Porcelains, and
>   hopefully nobody starts using "local" before all shells that matter
>   support it (notably, ksh from AT&T Research does not support it yet).
>
> For the purpose of git-prompt, I think it should be OK ...
> to declare that we now support shells
> other than bash and zsh as long as they are reasonably POSIX and
> support "local" that is dynamic.

I have to admit I missed "in our test suite". Right, so no "local" in Porcelains, but yes in the test suite.

But yes, agreed, because it supports so many more shells. The commit "git-prompt: ta-da! document.." does document it.

> (without
> "local", it is harder, if not impossible, to clobber end-user's
> shell variable namespace with various temporaries we need to use
> during prompt computation)

It actually is technically possible with git-prompt.sh, with 1 LOC. See the "anecdote" at end of the same "ta-da!" commit message which does exactly that. Though for obvious reason we can't really do that.

> Do we know what kind of "local" is ksh93 adding?  The same as their
> "typeset" that is not dynamic?  That is so different from what others
> do and scripts expect to be all that useful, I am afraid.

I would think it has to be similar enough to other shells, or else it creates a compatibility nightmare IMO. But that's a guess.

Somewhat off topic, so apologies if this shouldn't be here:

As for the Porcelains, I have to assume that it can be unpleasant to maintain big scripts without "local". Would there be an interest in adding a facility with the same semantics as "local", but posix compliant (and also posix-ish shells), for use in Porcelains?

It's not a drop-in replacement, but the syntax is reasonable IMO:
    locals myfunc x y
    _myfunc () {
        echo "$? $1 $2"
        x=1 y=2
        return 33
    }
    x=x; unset y
    (exit 42) || myfunc foo bar
    echo "$? $x ${y-unset}"
Prints:
    42 foo bar
    33 x unset

"locals myfunc x y" creates a wrapper function "myfunc" which saves the state of $x and $y, calls _myfunc "$@", then restores the state (and propagates the initial and final $? appropriately). Recursion is supported, the wrapper doesn't create additional variables, and no subshells are used at the wrapper (also not at "locals").

The implementation of "locals" is small (10-20 LOC), but we can't expect scripts to embed it, so it would need to be sourced (dot).

If there is interest in such thing, let me know, and I can submit a patch (independent of this patchset) to adds such file which can then be sourced by other scripts in order to use "locals".

Unrelated, and it might not mean much, but I did want to thank you for maintaining git all those years.

Previous: Junio C HamanoNext: Avi Halachmi via GitGitGadget
Message 27 of 80 in “git-prompt: support more shells”
  1. 0/8 git-prompt: support more shellsAvi Halachmi via GitGitGadget, Jul 23, 2024
  2. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  3. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  4. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  5. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  6. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  7. Junio C HamanoJul 23, 2024
  8. avihJul 24, 2024
  9. 6/8 git-prompt: add fallback for shells without $'...'Avi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  10. Junio C HamanoJul 23, 2024
  11. avihJul 24, 2024
  12. avihJul 25, 2024
  13. avihJul 25, 2024
  14. Junio C HamanoJul 25, 2024
  15. avihJul 25, 2024
  16. Junio C HamanoJul 25, 2024
  17. avihAug 14, 2024
  18. Junio C HamanoAug 14, 2024
  19. avihAug 15, 2024
  20. Junio C HamanoAug 15, 2024
  21. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  22. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Jul 23, 2024
  23. brian m. carlsonJul 23, 2024
  24. avihJul 24, 2024
  25. Junio C HamanoJul 24, 2024
  26. Junio C HamanoJul 24, 2024
  27. avihJul 24, 2024
  28. 0/8 git-prompt: support more shells v2Avi Halachmi via GitGitGadget, Aug 15, 2024
  29. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  30. Patrick SteinhardtAug 16, 2024
  31. avihAug 16, 2024
  32. Patrick SteinhardtAug 16, 2024
  33. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  34. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  35. Patrick SteinhardtAug 16, 2024
  36. avihAug 16, 2024
  37. Patrick SteinhardtAug 16, 2024
  38. avihAug 16, 2024
  39. Patrick SteinhardtAug 16, 2024
  40. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  41. Junio C HamanoAug 15, 2024
  42. avihAug 16, 2024
  43. Junio C HamanoAug 16, 2024
  44. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  45. Junio C HamanoAug 15, 2024
  46. avihAug 15, 2024
  47. Junio C HamanoAug 15, 2024
  48. avihAug 15, 2024
  49. 6/8 git-prompt: don't use shell $'...'Avi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  50. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  51. Patrick SteinhardtAug 16, 2024
  52. avihAug 16, 2024
  53. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Aug 15, 2024
  54. Junio C HamanoAug 15, 2024
  55. Patrick SteinhardtAug 16, 2024
  56. 0/8 git-prompt: support more shells v3Avi Halachmi via GitGitGadget, Aug 17, 2024
  57. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  58. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  59. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  60. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  61. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  62. Eric SunshineAug 17, 2024
  63. avihAug 17, 2024
  64. Junio C HamanoAug 17, 2024
  65. avihAug 17, 2024
  66. 6/8 git-prompt: don't use shell $'...'Avi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  67. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  68. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Aug 17, 2024
  69. 0/8 git-prompt: support more shells v4Avi Halachmi via GitGitGadget, Aug 20, 2024
  70. 1/8 git-prompt: use here-doc instead of here-stringAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  71. 2/8 git-prompt: fix uninitialized variableAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  72. 3/8 git-prompt: don't use shell arraysAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  73. 4/8 git-prompt: replace [[...]] with standard codeAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  74. 5/8 git-prompt: add some missing quotesAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  75. 6/8 git-prompt: don't use shell $'...'Avi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  76. 7/8 git-prompt: ta-da! document usage in other shellsAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  77. 8/8 git-prompt: support custom 0-width PS1 markersAvi Halachmi (:avih) via GitGitGadget, Aug 20, 2024
  78. Junio C HamanoAug 20, 2024
  79. avihAug 20, 2024
  80. avihAug 28, 2024

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.