You must first sign up to be able to contribute.

Version 11 (modified by chtito, 11 years ago)
added the "skeleton" arguments: default, rotate

zsh Completion file


Save the following in a file called _symfony and put it in the zsh function directory (/usr/share/zsh/site-functions on Mac OS X).

You will then have to issue compinit in a terminal and the new completion file should now be used along with all the others.


All the completion that you might dream of are supported:

  • application
  • modules
  • model classes
  • plugins
  • environments
  • synchronisation environments
  • fixtures
#compdef symfony

typeset -A opt_args

    _wanted application expl 'application' compadd $(command ls -1 apps 2>/dev/null| sed -e 's/ /\\ /g')

    local datapath
    datapath=$(command pwd| sed -e 's#$#/data#')
    _files -W $datapath

    _wanted module expl 'module' compadd $(command ls -1 apps/$words[2]/modules 2>/dev/null| sed -e '/^.*:$/d')

      _wanted model expl 'model' compadd $(command find lib/model -maxdepth 1 -name '*.php' -exec basename {} .php \; | grep -v Peer\$  )

      compadd $(command find lib/model -maxdepth 1 -name '*.php' -exec basename {} .php \; | grep -v Peer\$ | tr "[:upper:]" "[:lower:]" )

#  compset -S '[^:]*';
  compadd -S  '' symfony/ pear/

#  compadd dev prod test
  compadd $(command cat apps/$words[2]/config/settings.yml | grep '^\w*:$' | sed -e 's/:$//' | grep -v all)

  _wanted environment expl 'environment' compadd $(command cat config/properties.ini 2>/dev/null | awk "/\[/, /\]/" | sed -e 's/^\[//' -e 's/\]$//' -e '/^symfony$/d')

  _wanted plugins expl 'available plugins' compadd $(command pear list-all -c symfony | sed -E '/^symfony/!d' | sed -E '/^symfony\/symfony/d' | sed -E 's/^symfony\/([a-zA-Z]+).*/\1/g')

  command pear list-all -c symfony | sed -E '/^symfony/!d' | sed -E '/^symfony\/symfony/d' | sed -E 's/^symfony\/([a-zA-Z]+).*/\1/g' >| ~/.zsh/cache/sfPlugins

  local cache_policy
  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  if [[ -z "$cache_policy" ]]; then
    zstyle ":completion:${curcontext}:" cache-policy _sfplugins_caching_policy
  typeset -g -a _sfpluginlist
  if ( (( #_sfpluginlist == 0 )) || _cache_invalid sfplugins) \
       && ! _retrieve_cache sfplugins; then
    _sfpluginlist=(${(f)"$(command pear list-all -c symfony | sed -E '/^symfony/!d' | sed -E '/^symfony\/symfony/d' | sed -E 's/^symfony\/([a-zA-Z]+).*/\1/g')"})
    _store_cache sfplugins _sfpluginlist
  sfpluginlist=(${_sfpluginlist#*	})

  # rebuild if cache is more than a week old
  oldp=( "$1"(Nmw+1) )
  (( $#oldp ))

  compadd $sfPlugins[@]

local -a _1st_arguments
  'clear-cache:clear cached information'
  'cc:clear cached information'
  'clear-controllers:clear the web directory of all non production controllers'

  'fix-perms:fix directories permissions'
  'freeze:freeze symfony libraries to a PEAR release'
  'unfreeze:revert the freeze command'

  'init-project:initialize a new symfony project'
  'new:initialize a new symfony project'

  'init-app:initialize a new symfony application'
  'app:initialize a new symfony application'

  'init-module:initialize a new symfony module'
  'module:initialize a new symfony module'

  'init-batch:initialize a new batch'
  'batch:initialize a new batch'

  'init-controller:initialize a new controller'
  'controller:initialize a new controller'

  'plugin-install:install a new plugin'
  'plugin-uninstall:uninstall a plugin'
  'plugin-upgrade:upgrade a plugin'
  'plugin-upgrade-all:upgrade all plugins'
  'propel-build-db:create database for current model'
  'propel-build-model:create classes for current model'
  'propel-build-schema:create schema.xml from existing database'
  'propel-build-sql:create sql for current model'
  'propel-build-all:propel-build-schema, propel-build-sql and propel-insert-sql'
  'propel-load-data:loads all data from fixtures'
  'propel-build-all-load:executes propel-build-all then propel-load-data'
  'propel-convert-yml-schema:create schema.xml from schema.yml'
  'propel-convert-xml-schema:create schema.yml from schema.xml'
  'propel-generate-crud:generate a new propel CRUD module'
  'propel-init-admin:initialize a new propel admin module'
  'propel-init-crud:initialize a new propel CRUD module'
  'propel-insert-sql:insert sql for current model'
  'disable:forwards the user to the unavailable module'
  'enable:enables the application and clears the cache'
  'purge-logs:clears the logs files in the log directory'
  'rotate-log:rotation of a log file'
  'server:launch symfony web server'
  'sync:synchronise project with another machine'
  'test:launch project test suite'

#local -a _tasks
#_tasks=$(command symfony -T | sed -e '/pakeGetopt:/d' -e 's/^  //g' -e 's/[ ]*>/:/g' -e '/^$/d' -e '/:$/d' -e '/=/d' -e 's/: /:/g'  )

  local context state line expl
  local -A opt_args 

  _arguments \
    '(-T --tasks)'{-T,--tasks}'[list of the symfony tasks]' \
    '(-V --version)'{-V,--version}'[version]' \
    '*:: :->subcmds' && return 0

  if (( CURRENT == 1 )); then
    _describe -t commands "symfony commands" _1st_arguments -V1

  local -a sfpluginlist

case "$words[1]" in

      _message 'application name'
      compadd main;;
      _message 'new project name';;
        _arguments :application:_sfapps :'new module name':;;
        _arguments :'skeleton name':"compadd default rotate";;
        _arguments :application:_sfapps :environment:_sfenvironments :"script name": :"debug?":"compadd true false";;
        _arguments :application:_sfapps :environment:_sfenvironments;;
        _arguments :application:_sfapps :environment:_sfenvironments :fixtures:_sffixtures;;
        _arguments :application:_sfapps;;
      _arguments :location:"compadd global local" :plug-in:"compadd -a sfpluginlist";;
        _arguments :application:_sfapps :what:"compadd template config";;
      _arguments :environment:_sfsyncenvironments :"real run?":"compadd go ''";;
        _arguments :application:_sfapps :module: :model:_sfmodels;;

return 1

_symfony "$@"