简体   繁体   中英

How do you override/remove default completions in fish shell?

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:

  • The new auto complete I defined for --help (correct)
  • The base defined auto complete for -h (wrong)
  • All the other 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?

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.

Eg ~/.config/fish/completions/python3.fish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM