Reputation: 18325
I am adding completions for a command's subcommand, however fish is retaining the built in completions for the base command, but those no longer apply for the subcommand. I want to disable those base command completions when using the subcommand.
So, to give a specific example, I am adding complete
completions for the python3 -m venv
command. As I stated, all the builtin python3
completions still show even though they no longer apply. So, when I type python3 -m venv -<TAB>
, I get the completions I've added (good!), but also all the default completions too (bad).
So I have this code:
function __fish_python_using_command
# make sure that the command (minus the first item) matches argv
set cmd (commandline -opc)
if [ (count $cmd) -le (count $argv) ]
return 1
end
set idx (math (count $argv)+1)
if [ "$argv" = "$cmd[2..$idx]" ]
return 0
end
return 1
end
complete -f -c python3 -n '__fish_python_using_command -m venv' -s h -l help -d 'Display help creating virtual Python environments'
After running this, when I type when I type python3 -m venv -<TAB>
I get:
--help
(correct)-h
(wrong)python3
base auto complete switches like -V
from complete --command python3 --short-option 'V' --description 'Display version and exit'
(I want to disable these)I have considered using the -e
flag to remove the defaults when you are in python3 -m venv
mode, but that seems like the wrong way to go about it. I'm stumped. How would one disable all existing completions once a subcommand mode is entered? Or would this require a fundamental change to the way the python3
fish builtin completions are structured?
Upvotes: 0
Views: 1520
Reputation: 15924
Fish loads completions from files in $fish_complete_path. This is a list of directories, like $PATH. Put your completions into a file named after the command with a ".fish" suffix in an earlier directory and it will take precedence.
E.g. ~/.config/fish/completions/python3.fish.
Upvotes: 3