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

Re: [PATCH v5] git-completion.bash: add support for path completion

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 13, 2013, 22:56 UTC
Message-ID
<7vsj64hetm.fsf@alter.siamese.dyndns.org>
In-Reply-To
<50F178C8.40806@gmail.com>
Manlio Perillo <manlio.perillo@gmail.com> writes:
Show 24 quoted lines
> Il 11/01/2013 23:02, Junio C Hamano ha scritto:
>> Manlio Perillo <manlio.perillo@gmail.com> writes:
>> 
>>> +# Process path list returned by "ls-files" and "diff-index --name-only"
>>> +# commands, in order to list only file names relative to a specified
>>> +# directory, and append a slash to directory names.
>>> +__git_index_file_list_filter ()
>>> +{
>>> +	# Default to Bash >= 4.x
>>> +	__git_index_file_list_filter_bash
>>> +}
>>> +
>>> +# Execute git ls-files, returning paths relative to the directory
>>> +# specified in the first argument, and using the options specified in
>>> +# the second argument.
>>> +__git_ls_files_helper ()
>>> +{
>>> +	# NOTE: $2 is not quoted in order to support multiple options
>>> +	cd "$1" && git ls-files --exclude-standard $2
>>> +} 2>/dev/null
>> 
>> I think this redirection is correct but a bit tricky;
>
> It's not tricky: it is POSIX:

I know that. It is an instance of "Even it is in POSIX, we may want to refrain using it, because some shells get it wrong, and it is easy to work it around".

>> effect during the execution of the { block } (in other words, it is
>> not about squelching errors during the function definition).
>
> What do you mean by "squelching"?
Silencing, not showing the end user.  Sending to /dev/null.
> I have added tcsh to the sh list, but it fails with:
> Badly placed ()'s.

tcsh (and csh) are not even in the Bourne shell family and is not expected to be able to run any non trivial POSIX shell scripts. The completion script for it does not dot-source this but instead lets bash read it, so it is fine.

Show 6 quoted lines
>> It however may affect zsh, which does seem to dot-source this file.
>> Perhaps zsh completion may have to be rewritten in a similar way as
>> tcsh completion is done (i.e. does not dot-source this file but ask
>> bash to do the heavy-lifting).
>
> Ok, I was wrong on assuming all modern shells were POSIX compliant.

Shells in csh family will never be, and being non-POSIX is not a crime. It only matters when such a shell is allowed to dot-source this script, and this script uses constructs that such a shell does not understand.

Show 7 quoted lines
> I will change the code to use a nested {} group.
>
>> This function seems to be always called in an subshell (e.g. as an
>> upstream of a pipeline), so the "cd" may be harmless, but don't you
>> need to disable CDPATH while doing this?
>
> I don't know.

The caller of this function figures out the value of $subdirname, and calls you; your "cd $subdirname" may not go to ./$subdirname as you expect, but to the $subdirname directory under one of the directories listed in CDPATH, before running ls-tree or ls-files.

Previous: Manlio PerilloNext: Manlio Perillo
Message 4 of 9 in “git-completion.bash: add support for path completion”
  1. git-completion.bash: add support for path completionManlio Perillo, Jan 11, 2013
  2. Junio C HamanoJan 11, 2013
  3. Manlio PerilloJan 12, 2013
  4. Junio C HamanoJan 13, 2013
  5. Manlio PerilloJan 12, 2013
  6. Junio C HamanoJan 13, 2013
  7. Felipe ContrerasApr 21, 2013
  8. Manlio PerilloApr 23, 2013
  9. Felipe ContrerasApr 27, 2013

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.