查看完成函数中变量的值

view value of variables in a completion function

我有found下面的zsh补全函数

#compdef _h h

_h() { 
    local curcontext="$curcontext" state line
 
    _arguments \
        '1: :->country'\
        '*: :->city'
 
    case $state in
    country)
        _arguments '1:Countries:(France Germany Italy)'
    ;;
    *)
        case $words[2] in
        France)
            compadd "$@" Paris Lyon Marseille
        ;;
        Germany)
            compadd "$@" Berlin Munich Dresden
        ;;
        Italy)
            compadd "$@" Rome Napoli Palermo
        ;;
        *)
            _files 
        esac
    esac
}

我想查看 (echo) 变量值 ($curcontext$state$line$words),但不确定在哪里或者如何显示输出(因为仅当我按下 tab 时才会触发完成功能)。

如何查看上述变量的值

OP在这里。我也在zsh-users GitHub page中问过这个问题。下面给出了一些额外的答案。

将以下行放入您的完成文件中。

echo "curcontext=$curcontext state=$state line=$line words=$words[@]"

如果您想在另一个终端中打印调试输出,请使用:

echo "curcontext=$curcontext state=$state line=$line words=$words[@]" > device_file_path # like /dev/pts/3

在要查看调试输出的终端中键入 tty 以获取其 device_file_path