Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete custom "git-foo" commands from "git foo" commandlines #7652

Merged
merged 1 commit into from Jan 25, 2021

Conversation

krobelus
Copy link
Member

@krobelus krobelus commented Jan 24, 2021

Since #7075, git-foo.fish files are sourced when Git completions are loaded.
However, at least Cobra (CLI framework for Go) provides completions like

complete -c git-foo ...

This means that completions are only offered when typing "git-foo "
and not on "git foo ". Fix this by forwarding the completion requests.

This patch breaks git-foo.fish files that directly add competions to "git" using

complete -c git -n '__fish_git_using_command foo' ...

Since we forward to "git-foo" which has no custom completions, "git foo"
would get default file completions. I don't know if this pattern is used
already. Since #7075 is not released yet, it is probably not common.

cc @soraxas

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
Copy link
Member

faho commented Jan 24, 2021

This seems like a good idea, particularly because it matches git's semantics - any command named "git-thing" is available as "git thing", but that means it can also be called as "git-thing". So a "git-thing.fish" should have complete -c git-thing!

@krobelus krobelus added this to the fish 3.2.0 milestone Jan 24, 2021
@soraxas
Copy link
Contributor

soraxas commented Jan 25, 2021

I too reckon this is a good addition to make custom git-foo completions available when TAB completing git foo.

About the

complete -c git -n '__fish_git_using_command foo' ...

pattern, they are used in projects such as

https://github.com/tj/git-extras/blob/96b95392ac35d3ff033403e399cb7cfb7e94750b/etc/git-extras.fish#L80

For those sort of patterns, I think the new patch would add a completion that forwards git foo to git-foo that doesn't work, but since we are still sourcing the original file (source $git_ext), the original completion commands should still work. (i.e. there will be one redundant completion command, but it shouldn't beak the existing functionality?)

@krobelus
Copy link
Member Author

(i.e. there will be one redundant completion command, but it shouldn't beak the existing functionality?)

The redundant completion command would cause fish to use file completions on git-extras , since no completions are defined for git-extras. I'll guard against that by only doing this if complete git-extras is nonempty. Then both ways work.

@soraxas
Copy link
Contributor

soraxas commented Jan 25, 2021

I see that make sense, it didn't occured to me that complete -C 'foo ' would provide the default filelist completions even if foo is not a valid command.

Are there any simple way to check for the existence of completion command other than a guard that looks like this?

complete | string match -qr -- '\s-c git-foo'

share/completions/git.fish Outdated Show resolved Hide resolved
@faho
Copy link
Member

faho commented Jan 25, 2021

Are there any simple way to check for the existence of completion command other than a guard that looks like this?

After loading, with #7321 it's

complete foo

(#7321 makes it so it filters by the command and the -c is optional)

@soraxas
Copy link
Contributor

soraxas commented Jan 25, 2021

I see! I was just testing the changes on my local machine to notice those old syntax errors, thanks for the clarification

Since fish-shell#7075, git-foo.fish files are sourced when Git completions are loaded.
However, at least Cobra (CLI framework for Go) provides completions like

	complete git-foo ...

This means that completions are only offered when typing "git-foo <TAB>"
and not on "git foo <TAB>". Fix this by forwarding the completion requests.
Take care to only forward if there are actually completions for "git-foo",
to avoid adding filename completions.
@krobelus krobelus merged commit 0916176 into fish-shell:master Jan 25, 2021
krobelus added a commit that referenced this pull request Feb 2, 2021
Some third party Git tools provide a man page, which we can at least use
for completing options.

The old logic excluded all generated completions for Git subcommands.
Instead, try to load completions for all available external subcommands.
We can use $PATH/git-* because /bin/git-add and friends were removed in Git
1.6.0 in 2008.

Closes #4358 (the "git-foo" wrapping was added in #7652)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
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.

None yet

3 participants