【问题标题】:Programming customized tab completion for zsh为 zsh 编程自定义选项卡完成
【发布时间】:2009-07-14 16:21:11
【问题描述】:

对不起,如果我的google fu太弱了,但是:我只是想调整zsh以便我可以完成标签

someappname -s

使用 ~/somedir 的内容(文件名)

例如:

someapp -s f<tab>

应该根据 ~/somedir 中以字母 f 开头的文件循环完成。所以我最终可能会得到一个命令行,例如:“someapp -s foobar”。

【问题讨论】:

    标签: zsh tabs completion tab-completion


    【解决方案1】:

    更简单的方法:

    compdef "_files -W ~/somedir -/" someappname
    

    【讨论】:

    • 如果someappname 只接受目录作为参数,您可以使用_directories 而不是_files
    【解决方案2】:

    好吧,我解决了这个问题:(source at github)

    #compdef diakonos
    
    typeset -A opt_args
    local context state line
    local sessiondir
    sessiondir=${HOME}/.diakonos/sessions
    
    _arguments -n -s -S \
      "-s[specify session]:session:_files -W $sessiondir" \
      "*:file:_files" \
      && return 0
    
    return 1
    

    我引用了http://www.linux-mag.com/id/1106(需要[免费]注册才能阅读),并从freenode上的#zsh获得了帮助。

    【讨论】:

    • 您还可以查看 Oliver Kiddle、Jerry Peek 和 Peter Stephenson 所著的From Bash to Z Shell一书。
    猜你喜欢
    • 2020-03-24
    • 2013-02-14
    • 2012-01-08
    • 2010-10-08
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多