I'm trying to create a ZSH auto completion script for Symfony's Console, I almost finished it but I block in the last part. I need to create an array thanks to a function returns, but I don't know how to process. Here's the code I wrote:
_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
If I execute the command line, it formats it in the proper way. But used with ZSH the output is like this:
acme:hello -- Hello
assets:install -- Installs
cache:warmup -- Warms
and the formatted function returns:
acme\:hello:Hello World example command
assetic\:dump:Dumps all assets to the filesystem
cache\:warmup:Warms up an empty cache
The words that are not displayed, are used as a command completion. Here's an example: Asciinema example.
If I take the returns and use it directly into the array, it works well.