Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autocomplete 嵌套控制函数的zsh补全_Autocomplete_Zsh_Oh My Zsh_Zsh Completion - Fatal编程技术网

Autocomplete 嵌套控制函数的zsh补全

Autocomplete 嵌套控制函数的zsh补全,autocomplete,zsh,oh-my-zsh,zsh-completion,Autocomplete,Zsh,Oh My Zsh,Zsh Completion,我正在为zsh编写完成函数。我把它作为我的基础。除了-h和-help选项外,它在大多数情况下都可以正常工作。这些函数的完成输出未对齐并重复多次(如下所示)。只有当(\u description,\u arguments等)出现在case结构中时,才会发生这种情况。 发生这种情况的原因以及如何修复这种行为 完成功能: #compdef test _test() { local context state state_descr line typeset -A opt_args

我正在为
zsh
编写完成函数。我把它作为我的基础。除了
-h
-help
选项外,它在大多数情况下都可以正常工作。这些函数的完成输出未对齐并重复多次(如下所示)。只有当(
\u description
\u arguments
等)出现在case结构中时,才会发生这种情况。 发生这种情况的原因以及如何修复这种行为

完成功能:

#compdef test
_test() {
    local context state state_descr line
    typeset -A opt_args
    _arguments \
        "(- 1 *)"{-h,--help}"[Help]" \
        "1: :->command" \
        "*:: :->args"

    case $state in
        command)
            _alternative 'arguments:custom arg:(a b c)'
            ;;
        args)
            _arguments \
              "-a[All]" \
              "-n[None]"
    esac
}
_test
#compdef test

_test() {
    ...

    return 0
}

_test
外壳输出:

> test -[TAB]
--help
-h
-- Help
--help
-h
-- Help
--help
-h
-- Help

我刚刚遇到了同样的问题。解决方案是从完成函数返回零:

#compdef test
_test() {
    local context state state_descr line
    typeset -A opt_args
    _arguments \
        "(- 1 *)"{-h,--help}"[Help]" \
        "1: :->command" \
        "*:: :->args"

    case $state in
        command)
            _alternative 'arguments:custom arg:(a b c)'
            ;;
        args)
            _arguments \
              "-a[All]" \
              "-n[None]"
    esac
}
_test
#compdef test

_test() {
    ...

    return 0
}

_test
我看到的所有完成脚本都使用
ret
变量,该变量最初为
1
,如果任何完成函数成功,则设置为
0

#compdef test
_test() {
    local context state state_descr line
    local ret=1

    typeset -A opt_args
    _arguments \
        "(- 1 *)"{-h,--help}"[Help]" \
        "1: :->command" \
        "*:: :->args" && ret=0

    case $state in
        command)
            _alternative 'arguments:custom arg:(a b c)' && ret=0
            ;;
        args)
            _arguments \
              "-a[All]" \
              "-n[None]" && ret=0
    esac

    return ret
}

_test
不过,我不知道他们为什么这么做