【问题标题】:Suppress filename/directory completion in fish shell抑制鱼壳中的文件名/目录完成
【发布时间】:2015-06-26 03:29:11
【问题描述】:

我正在为Hub 编写完成脚本。

这是我的第一个完成脚本,我遇到了一些问题。从 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.'

现在,当输入 hub <tab> 时,它会正确地向我显示 helpalias 作为可能的补全。但是在输入hub alias <tab> 之后,它会显示一个目录列表,即使我在那里提供了-f 选项。

这里有什么问题?为什么会这样?有没有办法在这种情况下抑制文件/目录完成?

我们将不胜感激。谢谢。

【问题讨论】:

    标签: git shell tab-completion fish


    【解决方案1】:

    AFAIK 不可能完全禁止制表符补全。如果没有可用的特定命令完成,您将始终获得文件,根据总比没有好的理论。

    -f 标志的作用是防止文件与您的选项一起显示:

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

    您将看到与alphabeta 混合在一起的文件。现在:

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

    文件因-f 标志而消失。

    将来,这些内容将被基于 docopt 的完成语法 (#478) 所包含,这应该会使其更直接。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      相关资源
      最近更新 更多