linux - zsh 中修改当前完成选项的 compopt 等效项是什么?

标签 linux bash shell zsh

我正在为 zsh 编写一个自动完成脚本,我想在某些条件下启用 nospace。 bash 等效脚本如下所示

_my_completion(){
  if something; then
    compopt -o nospace
  fi
}

complete -F _my_completion <exec>

如何在 zsh 中实现相同的目标?

最佳答案

使用 -S '' 可以实现类似的效果。如 compadd论证,如你所见:

_my_completion(){
  # Here you can access ${words[@]}, $BUFFER, $CURSOR, $NAME, $CURRENT...
  if something; then
    completions_array=(foo bar baz)

    # `-S ''` is the equivalent of `compopt -o nospace`
    compadd -S '' -a completions_array
  fi
}

compdef _my_completion <exec>

如果您熟悉 bash 补全,您可以在 this script that loads the bash completions in ZSH 中了解 zsh 补全的比较情况。 .

关于linux - zsh 中修改当前完成选项的 compopt 等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48000023/

相关文章:

linux - 使用现有主目录安装 Ubuntu

bash - 在 bash 变量中找到一个子字符串

bash - 从 linux bash 中的函数分配局部变量一个新值

Bash - <<EOF 和 <<'EOF' 之间的区别

c - 我们可以使用 c 在 linux 中创建一个进程有多少种方法

python - 在 Python 脚本中比较 SNMP OID

mysql - 如何将 time_t 字段存储到 MySQL 日期时间?

linux - bash:文件不存在则创建,否则检查是否可写

linux - 在 Unix while-do 循环中,比较条件失败

shell - 如何在 korn shell 中转义逗号?