简体   繁体   English

如何在鱼壳中覆盖/删除默认补全?

[英]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. 我正在为命令的子命令添加补全,但是fish保留了基本命令的内置补全,但不再适用于该子命令。 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. 因此,举一个具体的例子,我为python3 -m venv命令添加了complete python3 -m venv As I stated, all the builtin python3 completions still show even though they no longer apply. 就像我说的那样,所有内置的python3仍然显示,即使它们不再适用。 So, when I type python3 -m venv -<TAB> , I get the completions I've added (good!), but also all the default completions too (bad). 因此,当我输入python3 -m venv -<TAB> ,我得到的是我添加的补全(好!),但也有所有默认补全(坏的)。

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: 运行此命令后,当我键入python3 -m venv -<TAB>输入:

  • The new auto complete I defined for --help (correct) 我为--help定义的新自动完成功能(正确)
  • The base defined auto complete for -h (wrong) -h的基本定义的自动完成(错误)
  • 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) 所有其他python3基本自动完成开关,例如complete --command python3 --short-option 'V' --description 'Display version and exit' -V complete --command python3 --short-option 'V' --description 'Display version and exit' (我想禁用它们)

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. 我已经考虑过在python3 -m venv模式下使用-e标志来删除默认值,但这似乎是错误的处理方式。 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? 还是需要对python3 fish内置python3的结构方式进行根本性的改变?

Fish loads completions from files in $fish_complete_path. Fish从$ fish_complete_path中的文件加载完成。 This is a list of directories, like $PATH. 这是目录列表,例如$ PATH。 Put your completions into a file named after the command with a ".fish" suffix in an earlier directory and it will take precedence. 将您的完成内容放在命令后命名的文件中,该文件的后缀为“ .fish”,该文件优先。

Eg ~/.config/fish/completions/python3.fish. 例如〜/ .config / fish / completions / python3.fish。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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