简体   繁体   English

在鱼壳中禁止文件名/目录完成

[英]Suppress filename/directory completion in fish shell

I am writing a completion script for Hub . 我正在为Hub编写完成脚本。

This being my first completion script, I have run into some problems. 这是我的第一个完成脚本,遇到了一些问题。 Taking inspiration from git.fish completion script, here is what I have till now: 从git.fish完成脚本中汲取灵感,这是我到目前为止所拥有的:

# statement starting with 'hub'
function __fish_hub_needs_command
    set cmd (commandline -opc)
    if [ (count $cmd) -eq 1 -a $cmd[1] = 'hub' ]
        return 0
    end
    return 1
end

# statement starting with 'hub COMMAND'
function __fish_hub_using_command
    set cmd (commandline -opc)
    if [ (count $cmd) -gt 1 ]
        if [ $argv[1] = $cmd[2] ]
            return 0
        end
    end
    return 1
end

# help
# show '--help' for every command
complete -f -c hub -n '__fish_hub_needs_command' -a help -d 'Display enhanced git-help(1)'
complete -f -c hub -n 'not __fish_hub_needs_command' -l help -d 'Display enhanced git-help(1)'

# alias
complete -f -c hub -n '__fish_hub_needs_command' -a alias -d 'Shows shell instructions for wrapping git.'
complete -f -c hub -n '__fish_hub_using_command alias' -s s -d 'Output shell script suitable for eval.'

Now, when type hub <tab> it shows me help and alias correctly as possible completions. 现在,当键入hub <tab>它会尽可能正确地显示helpalias But after typing hub alias <tab> it shows me a list of directories even when I have provided the -f option there. 但是在输入hub alias <tab>之后,即使我在其中提供了-f选项,它也会显示目录列表。

What is wrong here? 怎么了 Why is that happening? 为什么会这样呢? Is there a way to suppress file/directory completion in such a scenario? 在这种情况下,有没有办法抑制文件/目录的完成?

Help would be appreciated. 帮助将不胜感激。 Thank you. 谢谢。

AFAIK it's not possible to totally suppress tab completions. AFAIK,不可能完全禁止制表符补全。 If no command-specific completion is available, you will always get files, under the theory that something is better than nothing. 如果没有特定于命令的完成功能,则总会得到文件,而总会有一些总比没有好的理论。

What the -f flag does is prevent files from being shown alongside your options: -f标志的作用是防止文件显示在您的选项旁边:

> complete -c test_cmd -a 'alpha beta'
> test_cmd <tab>

you will see files intermixed with alpha and beta . 您将看到文件与alphabeta混合在一起。 Now: 现在:

> complete -f -c test_cmd -a 'gamma'
> test_cmd <tab>

the files are gone because of the -f flag. 由于-f标志,文件不见了。

In the future this stuff will be subsumed by a docopt-based completion syntax ( #478 ) which should make it more straightforward. 将来,这些内容将被基于docopt的完成语法( #478 )所包含,这将使其更直接。

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

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