8000 Add support for git-* command auto-completion by soraxas · Pull Request #7075 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content

Add support for git-* command auto-completion#7075

Merged
faho merged 3 commits intofish-shell:masterfrom
soraxas:git-custom-command-completion
Jun 20, 2020
Merged

Add support for git-* command auto-completion#7075
faho merged 3 commits intofish-shell:masterfrom
soraxas:git-custom-command-completion

Conversation

@soraxas
Copy link
Contributor
@soraxas soraxas commented Jun 2, 2020

Fixes issue #7071

Description

This PR addresses #7071 by loading git-*.fish completion in the main git.fish.

This approach addresses the following

  1. This does not add overheads to the existing git if the user had not installed any git-*.fish completion file, other than the searches for completion file during initialisation.
  2. Even if the main-repo or vendor provides some git-*.fish completion file, this approach won't loads them if the user had not installed the executable. Therefore, it won't clutter the shell by loading unnecessary completion.
  3. This follows the traditional loading approach where it only loads the first completion file git-*.fish it founds.
  4. It directly addresses the issue of currently there is no way (other than eager loading by user) to add completions for git <foo>. This approach allows you to add git-foo.fish to your completion file and it will load it whens git is invoked.
  5. By looking at the current git.fish it already tries to provide completion for custom git-* executable, so it makes sense to also load their completion, if exists, afterwards.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@faho faho added this to the fish 3.2.0 milestone Jun 2, 2020
@krobelus
Copy link
Contributor
krobelus commented Jun 2, 2020

This is a really nice approach! We can extend it to similar commands in future.

@faho
Copy link
Member
faho commented Jun 4, 2020

One problem with this approach:

It reads the git-$COMMAND autogenerated files in ~/.local/share/fish/generated_completions.

I'm not sure how to solve it. In a pinch skipping that directory (including checking $XDG_DATA_HOME) would probably do.

@soraxas
Copy link
Contributor Author
soraxas commented Jun 5, 2020

Hmm indeed, those ones that are generated from man page.

So I just checked and in fact, since those git-* man page has no associated executable, the code would reject them with the

not command -q $cmd
and continue

guard. (e.g. even though there are bunch of things like git-pull.fish and git-send-email.fish completion files in $XDG_DATA_HOME/generated_completions/, since there are no associated executable (e.g. no such git-pull standalone command exists), the command -q git-pull would fails.

Having said that, I'm not sure how useful those auto-generated completions are for custom git-* command (um probably?). If we want to save reductant check of command -q within generated_completions we can probably skip the auto-gen directory without much harm

@faho
Copy link
Member
faho commented Jun 5, 2020

So I just checked and in fact, since those git-* man page has no associated executable, the code would reject them with the

Indeed.

I'd still rather go through the directory list to remove it. E.g.

# Get the path to the generated completions
# If $XDG_DATA_HOME is set, that's it, if not, it will be removed and ~/.local/share will remain.
set -l generated_path $XDG_DATA_HOME/fish/generated_completions ~/.local/share/fish/generated_completions

# We don't want to modify $fish_complete_path here, so we make a copy.
set -l complete_dirs $fish_complete_path

# Remove the path to the generated completions if it is in the list
set -l ind (contains -i -- $generated_path[1] $complete_dirs); and set -e complete_dirs[$ind]

for git_ext in $list/git-*.fish
# ...

@soraxas
Copy link
Contributor Author
soraxas commented Jun 9, 2020

Thanks @faho for your kind suggestions

@faho faho merged commit eb4f867 into fish-shell:master Jun 20, 2020
@faho
Copy link
Member
faho commented Jun 20, 2020

Merged. Thank you and sorry for the delay!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0