【问题标题】:is `cap` a reserved word? - zsh completion?`cap` 是保留字吗? - zsh 完成?
【发布时间】:2014-01-25 17:41:41
【问题描述】:

我正在尝试为 ZSH 创建 Capistrano mutilstage 补全:

$ cap |
production staging


$ cap production |
deploy                       -- Deploy a new release
deploy:bundle                -- Bundle
...

完成代码:

#compdef cap
#autoload

# /Users/pablo/.oh-my-zsh/custom/plugins/capistrano_custom/_capistrano_custom

local curcontext="$curcontext" state line ret=1
local -a _configs

_arguments -C \
  '1: :->cmds' \
  '2:: :->args' && ret=0

_cap_tasks() {
  if [[ ! -f .cap_tasks~ ]]; then
    echo "\nGenerating .cap_tasks~..." > /dev/stderr
    cap -v --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~
  fi
  cat .cap_tasks~
}

_cap_stages() {
  find config/deploy -name \*.rb | cut -d/ -f3 | sed s:.rb::g
}

case $state in
  cmds)
    if [[ -d config/deploy ]]; then
      compadd `_cap_stages`
    else
      compadd `_cap_tasks`
    fi
    ret=0
    ;;
  args)
    compadd `_cap_tasks`
    ret=0
    ;;
esac

return ret

问题:

#compdef cap 不起作用。如果我输入 cap 和 [TAB] 它不会执行完成,但换句话说(即shipit)可以正常工作。

有什么想法吗?

解决方案:

cap is really a reserved word 似乎我们不能将它与#compdef cap 一起使用。

我想知道 capcapistrano 之前的补全是如何工作的(可能是 ZSH 的旧版本)。

两种解决方案都使用shipit 而不是cap

$ shipit |
production staging

$ shipit production |
deploy                       -- Deploy a new release
deploy:bundle                -- Bundle
...

【问题讨论】:

  • “有什么想法吗?” -- 使用xcap,或其他合适的名称。
  • alias xcap="cap" 我试过了,但还是不行。 ZSH 不喜欢用cap 完成。
  • 别名不起作用;原始名称也不得保留。
  • 我在问题中添加了一个“解决方案”。谢谢!
  • 嗨,Pablo,我如何使用你的自定义插件?

标签: zsh oh-my-zsh zsh-completion


【解决方案1】:

是的,cap 是 ZSH 内置的。引用from zsh docs:

zsh/cap 模块用于操作 POSIX.1e (POSIX.6) 能力集。 [...]。该模块中的内置函数是:

cap [ capabilities ] 将 shell 的进程能力集更改为 指定的功能,否则显示 shell 的当前 能力。

【讨论】:

  • 否,除非您使用 xcap 或类似的东西来自动完成。您还可以尝试使用zmodload -u cap(如果它是一个模块)卸载cap,或者在不使用cap(如果它在编译时启用)的情况下重新编译zsh。后者不是一个好主意,除非你绝对确定你永远不需要cap
  • zmodload: no such module cap 我认为它不是一个模块。 ://
  • 在这种情况下,为自动完成找到另一个关键字。也许capixcap...
猜你喜欢
  • 2016-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多