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

Re: [PATCH] Simplest update to bash completions to prevent unbounded variable errors

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 13, 2009, 15:20 UTC
Message-ID
<20090113152047.GO10179@spearce.org>
In-Reply-To
<496C1F5F.9020604@tedpavlic.com>
Ted Pavlic <ted@tedpavlic.com> wrote:
> Another try at fixing bash completions in "set -u" environments.

I agree with Junio; setting -u in your interactive shell is as bad as export CDPATH. Its crazy.

> Additionally added some comments and omitted things like Vim modelines.

These are orthogonal to the -u corrections. They should be in a different patch. The comments are wecome. The '#!bash' looks like a good idea. But a vim specific modeline, I don't like, for the reasons Junio has already stated.

Show 6 quoted lines
> +# __gitdir accepts 0 or 1 arguments (i.e., location)
> +# returns location of .git repo
>  __gitdir ()
>  {
> -	if [ -z "$1" ]; then
> +	if [ $# -eq 0 ] || [ -z "$1" ]; then

This is one of those places where [ -z "${1-}" ] is likely easier to read then the || usage you have introduced. We don't care if we got no args, or we got one that is the empty string, either way the $1 cannot be a gitdir and we need to guess it.

Show 7 quoted lines
> @@ -111,7 +116,7 @@ __git_ps1 ()
>  			fi
>  		fi
>
> -		if [ -n "$1" ]; then
> +		if [ $# -gt 0 ] && [ -n "$1" ]; then
>  			printf "$1" "${b##refs/heads/}$r"
Eh, I'd rather see [ -n "${1-}" ] over the && test.
Show 6 quoted lines
> -complete -o default -o nospace -F _git git
> -complete -o default -o nospace -F _gitk gitk
> +complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
> +	|| complete -o default -o nospace -F _git git
> +complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
> +	|| complete -o default -o nospace -F _gitk gitk

Why are we switching to bashdefault? Is this an unrelated change from the -u stuff and should go into its own commit, with its own justification?

-- 
Shawn.
Previous: Ted PavlicNext: Ted Pavlic
Message 2 of 4 in “Simplest update to bash completions to prevent unbounded variable errors”
  1. Simplest update to bash completions to prevent unbounded variable errorsTed Pavlic, Jan 13, 2009
  2. Shawn O. PearceJan 13, 2009
  3. Ted PavlicJan 13, 2009
  4. Shawn O. PearceJan 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.