Is it possible to explicitly inherit completions for a git
alias?
#8831
-
I have an issue relating to command completion inheritance with function _git_compare --wraps 'git diff'
# ...
end When calling this function directly, I get the inherited completions from [alias]
compare = ! fish -c '_git_compare $argv' -- This works well, except for the fact that What I figured I could do is explicitly tell complete -c git -w _git_compare -n '__fish_git_using_command compare'
complete -c git -w 'git diff' -n '__fish_git_using_command compare' But neither of those seem to work. Is there any way I can inherit command completions from |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
See #5412. The git completions specifically allow this: set -g __fish_git_alias_compare diff |
Beta Was this translation helpful? Give feedback.
-
On Thu, Mar 24, 2022 at 08:56:07AM -0700, Jamin Thornsberry wrote:
why don't you make it a script called
These don't do what you expect. fish reads each of those lines as two independent completions:
maybe this should be an error
BTW, a more realistic feature we should support are multi-level aliases:
completion for |
Beta Was this translation helpful? Give feedback.
-
On Thu, Mar 24, 2022 at 08:56:07AM -0700, Jamin Thornsberry wrote:
I have an issue relating to command completion inheritance with `git` aliases, and I'm not quite sure how to solve it or whether it's even possible. I have a `fish` function I've written that essentially acts like a `fzf`-enhanced version of `git diff`:
```fish
function _git_compare --wraps 'git diff'
# ...
end
```
When calling this function directly, I get the inherited completions from `git diff`, as expected. Thing is, I don't want to call this function directly, I want it as a `git` alias, so I've added it to my `.gitconfig` like this:
```ini
[alias]
compare = ! fish -c '_git_compare $argv' --
why don't you make it a script called `git-compare`?
Then you don't need the alias and running
`complete git-compare --wraps 'git diff'`
is enough to get custom completions, also for `git compare` (might need to
restart your shell because we enumerate all possible git-foo commands only
when loading git completions).
```
This works well, except for the fact that `fish` loses the command completions from `git diff`. This is totally understandable, I wouldn't expect `fish` to parse the content of a command that I'm passing to a `fish` shell in a `git` alias, that seems like a terribly complex thing to do programmatically.
What I figured I could do is explicitly tell `fish` with the `complete` command how I'd like my `git compare` alias to inherit completions:
```fish
complete -c git -w _git_compare -n '__fish_git_using_command compare'
complete -c git -w 'git diff' -n '__fish_git_using_command compare'
These don't do what you expect. Fish reads each of those lines as two independent completions:
$ complete git -w 'git diff' -n '__fish_git_using_command compare'
$ complete git
complete git -n '__fish_git_using_command compare'
complete git --wraps 'git diff'
maybe this should be an error
```
But neither of those seem to work. Is there any way I can inherit command completions from `git show` for my `git compare` alias?
BTW, a more realistic feature we should support are multi-level aliases:
[alias]
a = b
b = diff
completion for `git a` works with bash's git completions but not with ours
|
Beta Was this translation helpful? Give feedback.
See #5412. The git completions specifically allow this: