0

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.

Cronos87
  • 1,816
  • 3
  • 12
  • 14
  • 1
    I can't help with your array problem, but you should be aware that you can condense all of your piped data cleanup, (sed,awk,sed,sed,...) into one call to awk. Read about the `sub()` function, it's a little different than `sed` but the regexps should be about the same. Good luck. – shellter Jan 28 '16 at 22:06
  • What's the issue here exactly? I didn't follow the various outputs and what's going on here exactly. – Etan Reisner Jan 29 '16 at 04:47

0 Answers0