ZSH Symfony控制台自动完成

时间:2016-01-28 22:00:53

标签: bash shell zsh zsh-completion

我正在尝试为Symfony的控制台创建一个ZSH自动完成脚本,我差点完成它但是我在最后一部分阻止了。由于函数返回我需要创建一个数组,但我不知道如何处理。 这是我写的代码:

_find_console () {
    echo "php $(find . -maxdepth 2 -mindepth 1 -name 'console' -type f | head -n 1)"
}

_console_get_command_list () {
    `_find_console` --no-ansi | \
        sed "1,/Available commands/d" | \
        awk '/ [a-z]+/ { print $0 }' | \
        sed -E 's/^[ ]+//g' | \
        sed -E 's/[:]+/\\:/g' | \
        sed -E 's/[ ]{2,}/\:/g'
}

_console () {
    local -a commands
    commands=(`_console_get_command_list`)
    _describe 'commands' commands
}

compdef _console php console
compdef _console console

如果我执行命令行,它会以正确的方式格式化它。但是与ZSH一起使用的输出是这样的:

acme:hello         -- Hello
assets:install     -- Installs
cache:warmup       -- Warms

并且格式化的函数返回:

acme\:hello:Hello World example command
assetic\:dump:Dumps all assets to the filesystem
cache\:warmup:Warms up an empty cache

未显示的单词用作命令完成。这是一个例子:Asciinema example

如果我接受返回并直接将其用于数组,那么效果很好。

0 个答案:

没有答案
相关问题