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

Already on GitHub? Sign in to your account

`complete -C` fails on subcommands #4093

Closed
Ambrevar opened this Issue Jun 3, 2017 · 5 comments

Comments

Projects
None yet
2 participants
Contributor

Ambrevar commented Jun 3, 2017

fish, version 2.5.0-430-g5e39efa4
OS: Arch Linux
Terminal: Urxvt 9.22

Works as expected:

fish -c 'complete -C"fish --"'

Outputs nothing:

fish -c 'complete -C"env LC_ALL=C fish --"'
fish -c 'complete -C"sudo fish --"'

Am I hitting a bug?

@krader1961 krader1961 added the question label Jun 4, 2017

Contributor

krader1961 commented Jun 4, 2017

Not so much a bug but a fundamental limitation. The first thing to note is that fish has no way to know that env or sudo are commands followed by another command which you might want help completing. We work around this by using a function named __fish_complete_subcommand in the completions for env and sudo. Type complete | grep 'command env' and note how it gets invoked. Now look at the definition of that function. It relies on the commandline builtin to get the current interactive command line. But since you're not running in an interactive context it can't fetch that information and thus has no idea what command to complete. If you just type env LC_ALL=C fish -- interactively then press <tab> you'll see the expected options for the fish command.

Contributor

Ambrevar commented Jun 4, 2017

complete | grep 'command env' outputs nothing and complete only outputs the aliases I've set.

complete --command l --wraps ls
...

Anyways, I've looked up the functions manually.

I'm trying to replace the fish completion menu with fzf using the code there: https://github.com/junegunn/fzf/wiki/Examples-(fish) (Completion).

Is there any workaround?

Generally speaking, it would be great if complete -C would effectively generate the same completion as <tab> does. This is related to #3469.

Contributor

krader1961 commented Jun 4, 2017

Completions aren't loaded until you try to use the command in the current shell. They're like autoloaded functions in that regard. So complete | grep 'command env' won't show it's completions unless you've actually used the command.

The current solution for nested commands is a bit of a hack. I hate to say never but it is improbable the current solution will ever be improved as it would be adding a hack on top of a hack. You could certainly open an enhancement request that the core completion logic include support for nested commands. But I wouldn't hold my breath waiting for it to be implemented.

Since in practice there are only a handful of commands commonly used which have this pattern (sudo and env being the only two that immediately come to mind) it should be easy enough to special-case them in your wrapper around the complete command.

Contributor

Ambrevar commented Jun 4, 2017

Too bad. I'll see if I can work around this gracefully though.

@krader1961 krader1961 closed this Jun 6, 2017

Contributor

Ambrevar commented Jun 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment