Permalink
Browse files

enhanced symfony2 plugin

  • Loading branch information...
miklos-martin committed Jan 15, 2013
1 parent c5d575c commit c5cbbaeffc9f6e8e393358a879b6ce456b21da21
Showing with 66 additions and 6 deletions.
  1. +66 −6 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
+for console_command in $SYMFONY_DO_COMPLETE_CONSOLE
+do
+ compdef _symfony2 $console_command
+done

0 comments on commit c5cbbae

Please sign in to comment.