首页 > 解决方案 > Zshell 完成调用另一个函数

问题描述

我为 tmux 编写了几个 zsh 函数。我正在尝试为其中一些功能添加自动完成功能,但遇到了麻烦。

其中一个功能tktmux kill-session. 此函数采用要终止的会话的名称,如果未提供,则回退到当前会话。

这是我的函数的样子:

function tk {
  if [ $# -ne 0 ]; then
    tmux kill-session -t $1
  else
    tmux kill-session
  fi
}

我还编写了一个active_tmux_sessions在其他一些地方使用的函数:

function active_tmux_sessions {
  tmux ls -F "#{session_name}" 2>/dev/null | cut -d: -f1
}

这是我将它们粘合在一起的方法。

function _tk() {
  compadd $(active_tmux_sesions)
}

compdef _tk tk

当我键入tk <tab>时,我收到此错误:

tk _tk:1: command not found: active_tmux_sesions
_tk:1: command not found: active_tmux_sesions
_tk:1: command not found: active_tmux_sesions

标签: zshprezto

解决方案


推荐阅读