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

Re: [PATCH] git-prompt.sh: shorter equal upstream branch name

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 1, 2014, 17:49 UTC
Message-ID
<xmqqppebptmj.fsf@gitster.dls.corp.google.com>
In-Reply-To
<542B7AF8.6080501@bbn.com>
Richard Hansen <rhansen@bbn.com> writes:
Show 5 quoted lines
>> and there is no hope to "fix" them to stick to
>> the bare-minimum POSIX,
>
> I don't think it'd be hard to convert it to pure POSIX if there was a
> desire to do so.

Not necessarily; if you make it so slow to be usable as a prompt script, that is not a "conversion". Bash-isms in the script is allowed for a reason, unfortunately.

> It would be unwise to go to great lengths to avoid Bashisms, but I think
> it would be smart to use POSIX syntax when it is easy to do so.  

In general, I agree with you. People who know only bash tend to overuse bash-isms where they are not necessary, leaving an unreadable mess.

For the specific purpose of Julien's "if the tail part of this string matches the other string, replace that with an equal sign", ${parameter/pattern/string} is a wrong bash-ism to use. But the right solution to count the length of the other string and take a substring of this string from its beginning would require other bash-isms ${#parameter} and ${parameter:offset:length}.

And that's fine.
Previous: Richard HansenNext: Julien Carsique
Message 5 of 9 in “git-prompt.sh: shorter equal upstream branch name”
  1. git-prompt.sh: shorter equal upstream branch nameJulien Carsique, Sep 30, 2014
  2. Richard HansenSep 30, 2014
  3. Junio C HamanoSep 30, 2014
  4. Richard HansenOct 1, 2014
  5. Junio C HamanoOct 1, 2014
  6. Julien CarsiqueOct 7, 2014
  7. Richard HansenOct 7, 2014
  8. Junio C HamanoOct 7, 2014
  9. Junio C HamanoSep 30, 2014

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.