From c5cbbaeffc9f6e8e393358a879b6ce456b21da21 Mon Sep 17 00:00:00 2001 From: mikka Date: Tue, 15 Jan 2013 21:23:31 +0100 Subject: [PATCH] enhanced symfony2 plugin --- plugins/symfony2/symfony2.plugin.zsh | 72 +++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/plugins/symfony2/symfony2.plugin.zsh b/plugins/symfony2/symfony2.plugin.zsh index 644266841..89e467f7b 100644 --- a/plugins/symfony2/symfony2.plugin.zsh +++ b/plugins/symfony2/symfony2.plugin.zsh @@ -1,13 +1,73 @@ # Symfony2 basic command completion +# And one step further + +: ${SYMFONY_COMPLETE_CONSOLE:=""} +: ${SYMFONY_COMPLETE_ENTITIES:=""} + +_SYMFONY_COMPLETE_CONSOLE=( + app/console +) + +SYMFONY_DO_COMPLETE_CONSOLE=($_SYMFONY_COMPLETE_CONSOLE $SYMFONY_COMPLETE_CONSOLE) + +_SYMFONY_COMPLETE_ENTITIES=( + doctrine:generate:crud + doctrine:generate:entities + doctrine:generate:form + generate:doctrine:crud + generate:doctrine:entities + generate:doctrine:form +) + +SYMFONY_DO_COMPLETE_ENTITIES=($_SYMFONY_COMPLETE_ENTITIES $SYMFONY_COMPLETE_ENTITIES) + +_symfony2 () +{ + #local asd=(echo $curcontext | tee) + + local console=$words[1] + + if [ ! -f "$console" ];then + return + fi + + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '*::options:->options' + + case $state in + (command) + if [ -z "$symfony2_command_list" ];then + _symfony2_command_list=$(_symfony2_get_command_list $console) + fi + compadd "$@" $(echo $_symfony2_command_list) + ;; + + (options) + needle=$line[1] + if [[ ${SYMFONY_DO_COMPLETE_ENTITIES[(i)$needle]} -le ${#SYMFONY_DO_COMPLETE_ENTITIES} ]]; then + if [ -z "$symfony2_entity_list" ];then + _symfony2_entity_list=$(_symfony2_get_entity_list $console) + fi + compadd "$@" $(echo $_symfony2_entity_list) + else + fi + ;; + esac +} _symfony2_get_command_list () { - app/console --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }' + $1 --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }' | sed -e 's/:/\:/g' } -_symfony2 () { - if [ -f app/console ]; then - compadd `_symfony2_get_command_list` - fi +_symfony2_get_entity_list () { + $1 doctrine:mapping:info | grep Bundle | cut -d ' ' -f 4 | awk '{ split($0, A, /\\/); for ( var in A ) { if ( match(A[var], /.*Bundle/) ) { bundle=A[var]; } } print bundle":"A[var] }' } -compdef _symfony2 app/console \ No newline at end of file +for console_command in $SYMFONY_DO_COMPLETE_CONSOLE +do + compdef _symfony2 $console_command +done