【问题标题】:How can I enable tab-completion for `@` path options to HTTPie in fish?如何在fish中为HTTPie的“@”路径选项启用制表符补全?
【发布时间】:2021-05-14 09:38:22
【问题描述】:

HTTPie 接受包含@ 符号选项的路径作为参数。不幸的是,它们似乎不适用于 fish 中的 shell 完成。相反,该选项被视为一个不透明的字符串。

要坚持使用the file upload example from the HTTPie documentation~/files/data.xml 的文件,我希望能够在键入时通过制表符完成文件名:

http -f POST pie.dev/post name='John Smith' cv@~/files/da<TAB>

但是,没有提供完成。

我已经安装了completions for fish from the HTTPie project,它们适用于短论和长论。该文件并未指定如何完成@ 参数。

此外,我研究了指定自己的完成,但我无法找到一种方法来使用任意前缀来处理文件完成。

如何为 HTTPie 的这些路径参数实现补全?

【问题讨论】:

    标签: fish tab-completion httpie


    【解决方案1】:

    目前,HTTPie 的 fish 补全没有使用 @ 的文件路径参数补全。关于这个有一个更通用的GitHub Issue open

    如果这是您想为自己或项目做的事情,您可能可以从HTTPie plugin for zsh+ohmyzsh 中为fish 实现获得一些灵感,以实现您想要的行为。

    【讨论】:

    • 感谢您的提示。不过,安装通用完成不是问题。如问题中所述,我已经手动安装了它们,但它们不包括路径的完成。请参阅我自己的答案,了解从那时起我如何实现路径完成的极简版本。
    【解决方案2】:

    我设法让路径参数的制表符完成,但需要注意一些警告。

    这增加了完成:

    complete -c http --condition "__is_httpie_path_argument" -a "(__complete_httpie_path_argument (commandline -t))"
    

    具有以下功能:

    function __is_httpie_path_argument
        set -l arg (commandline -t)
        __match_httpie_path_argument --quiet -- $arg
    end
    
    function __match_httpie_path_argument
        string match --entire --regex '^([^@:=]*)(@|=@|:=@)(.*)$' $argv
    end
    
    function __complete_httpie_path_argument
        __complete_httpie_path_argument_helper (__match_httpie_path_argument -- $argv[1])
    end
    
    function __complete_httpie_path_argument_helper
        set -l arg $argv[1]
        set -l field $argv[2]
        set -l operator $argv[3]
        set -l path $argv[4]
    
        string collect $field$operator(__fish_complete_path $path)
    end
    

    需要注意的是,这不会扩展任何变量或波浪号 ~。它基本上只适用于普通路径——相对路径或绝对路径。

    【讨论】:

    • 我可以通过用complete --do-complete="ls $path" 替换__fish_complete_path $path 来使用一个hackish 解决方法,但这也不能完美地工作。
    猜你喜欢
    • 2014-01-17
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多