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

Re: [PATCH] Simple update to bash completions to prevent unbound variable errors.

From
Ted Pavlic <ted@tedpavlic.com>
Date
Jan 13, 2009, 04:30 UTC
Message-ID
<496C18D8.9070707@tedpavlic.com>
In-Reply-To
<7vy6xfew2n.fsf@gitster.siamese.dyndns.org>
>> A vim modeline has also been added for consistency.
>
> Yuck.
Better that than have a mixture of spaces and tabs.
>> +# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
>> +# returns text to add to bash PS1 prompt (includes branch name)
>
> Good.  Would be better if you described what $1 and $2 mean.
In that case, there's only $1 (the format string).

Note that in most cases, I didn't know what $1 and $2 were. I was just trying to fix it so that it would work on my system.

Show 6 quoted lines
>> -		if [ -n "$1" ]; then
>> +		if [ $# -gt 0 ]&&  [ -n "$1" ]; then
>
> I found the previous round's [ -n "${1-}" ] much easier to read, if we were to
> do this.  If -n "${1-}", then "$1" is definitely set so nothing need to
> change in the then ... else part.

Hey -- I agree, but no one else liked ${1-}. And hg's bash completion seems far superior because they avoid ever having to worry about it. They actually thought about the arguments ahead of time.

>> +# __gitcomp_1 requires 2 arguments
>
> ... and $1 and $2 mean?
No clue. Patches are welcome.
> Yuck.  If you are taking advantage of the fact that "local one"
> will bind one to emptiness anyway, can't you do something like:
>
> 	local one=${1-} two=${2-} cur=${3-} four=${4-}
Why even use one, two three, and four then?

I had ${#-} throughout, but I was told that that was ugly. So the best I could do was come up with the above mess.

--Ted
-- 
Ted Pavlic <ted@tedpavlic.com>

   Please visit my ALS association page:
         http://web.alsa.org/goto/tedpavlic
   My family appreciates your support in the fight to defeat ALS.
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 9 in “Simple update to bash completions to prevent unbound variable errors.”
  1. Simple update to bash completions to prevent unbound variable errors.Ted Pavlic, Jan 13, 2009
  2. Junio C HamanoJan 13, 2009
  3. Boyd Stephen Smith Jr.Jan 13, 2009
  4. Ted PavlicJan 13, 2009
  5. Ted PavlicJan 13, 2009
  6. Teemu LikonenJan 13, 2009
  7. Junio C HamanoJan 13, 2009
  8. Ted PavlicJan 13, 2009
  9. Junio C HamanoJan 13, 2009

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.