2

Is there a way to wrap a command with options in a function, so that completions for that command with the options are shown?

For example, I want to be able to do this:

function remove --wraps='pikaur -R'
    pikaur -R $argv;
end

so that using remove will complete with the installed packages, but this doesn't work.

1 Answers1

0

The --wraps argument only accepts a bare command. You can use --wraps='pikaur' but not --wraps='pikaur -R'.

If the completions you want are only triggered when the -R flag is given, using --wraps may not be enough. You would need to add your own completions file. Fortunately, Fish makes this very simple.

Is there a command that lets you query or list the valid options? I'm not familiar with pikaur, but for example, let's say the valid arguments to your function were given given by a command like pikaur ls or pikaur query, or perhaps they're subdirectories of /etc/pikaur. If there is such a command, you can create a completions file for your function (i.e. if your function is located in ~/.config/fish/functions/remove.fish, then create ~/.config/fish/completions/remove.fish) with the following contents:

complete -c remove --no-files --arguments "(<query command>)"

Note: If you'd like to refer to existing completions, you can see inspect the directories listed by echo $fish_complete_path.