Development

BashCompletion

You must first sign up to be able to contribute.

Symfony Bash auto-completion

Add this to your bash completion :

  • Debian / Ubuntu / Mandriva : /etc/bash_completion.d/symfony
  • Redhat : /etc/profile.d/symfony
  • SLES : /etc/bash_completion.d/symfony.sh
_symfony()
{            
  local cur prev action
  COMREPLY=()   
  cur=${COMP_WORDS[COMP_CWORD]}
  prev=${COMP_WORDS[COMP_CWORD-1]}
  action=${COMP_WORDS[1]}
  
  case "$prev" in
    init-module|propel-generate-crud|propel-init-crud|propel-init-admin|propel-load-data|propel-build-all-load)
      COMPREPLY=( $( compgen -W "$( ls --color=n -1 apps 2>/dev/null| sed -e 's/ /\\ /g' )" -- $cur ))
      return 0
    ;;
    init-project)
      COMPREPLY=( $( compgen -W "$( basename $PWD )" -- $cur ))
      return 0
    ;;
    init-app)
      COMPREPLY=( $( compgen -W "frontend backend" -- $cur))
      return 0
    ;;    
    symfony)
      COMPREPLY=( $( compgen -W "$( symfony -T | awk '/^  /' | cut -d' ' -f3 )" -- $cur ) )
      return 0
    ;;    
    plugin-install)
    COMPREPLY=( $( compgen -W 'local global' -- $cur ) )
    return 0
    ;;
    global|local)
    COMPREPLY=( $( compgen -W 'symfony/' ) )
    return 0
    ;; 

    *)
      case "$action" in
        propel-generate-crud|propel-init-crud|propel-init-admin)
          if (($COMP_CWORD == 3)); then
            COMPREPLY=( $( compgen -W "$( find lib/model -maxdepth 1 -name '*.php' -exec basename {} .php \; |grep -v Peer\$| tr [:upper:] [:lower:] )" -- $cur ) )
          elif (($COMP_CWORD == 4)); then
            COMPREPLY=( $( compgen -W "$( find lib/model -maxdepth 1 -name '*.php' -exec basename {} .php \; |grep -v Peer\$ )" -- $cur ) )
            
          fi
          return 0
          ;;
      esac
      return 0
    ;;
      sync)
          if (($COMP_CWORD == 3)); then
            COMPREPLY=( $( compgen -W 'go' -- $cur))
          fi
          return 0
          ;;
  
  esac




    return 0  
}
       
complete -F _symfony symfony

Alternatively you can put the above code in ~/.bash-completion and add this line to your .bashrc:

[ -f ~/.bash-completion ] && source ~/.bash-completion

---

Update

I'd like to propose an updated version of the bash_completion script for symfony that supports both symfony 1.0 and symfony 1.1, as well as properly tab completing symfony commands regardless of whether you are using a version of symfony installed on your system via PEAR or a similar mechanism, or symfony in a frozen installation (As ususal, YMMV. This completion script works fine for me using symfony 1.0.16 installed via PEAR and a sf_sandbox using symfony 1.1.0-RC1. Also, this will most probably not work correctly if you attempt to use this with a version of symfony less than 1.0).

Without further ado...

_symfony()
{            
  local cur prev action
  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}
  prev=${COMP_WORDS[COMP_CWORD-1]}
  action=${COMP_WORDS[1]}

  case "$prev" in
    "init-module"|"propel-generate-crud"|"propel-init-crud"|"propel-init-admin"|"generate:module"|"propel:generate-crud"|"propel:init-admin")
      COMPREPLY=( $( compgen -W "$( ls -1 apps 2>/dev/null | sed -e 's/ /\\ /g' | sed -e 's/\/$//g' )" -- $cur ) )

      return 0
    ;;

    "init-project"|"generate:project")
      COMPREPLY=( $( compgen -W "$( pwd | perl -pe "s/^.*?([^\/]+)$/\$1/g" )" -- $cur ) )

      return 0
    ;;

    "init-app"|"generate:app")
      COMPREPLY=( $( compgen -W "frontend backend" -- $cur ) )

      return 0
    ;;    

    "sync")
      if (($COMP_CWORD == 3)); then
        COMPREPLY=( $( compgen -W 'go' -- $cur))
      fi

      return 0
    ;;

    *symfony)
      SYMFONY_VERSION=$( $prev -V | sed 's/^symfony version //g' | awk -F '.' '{print $1 "." $2;}' )

      case "$SYMFONY_VERSION" in
        0.*)
          # Versions less than 1.0 are not supported.
          COMPREPLY=()
        ;;

        "1.0")
          COMPREPLY=( $( compgen -W "$( $prev -T | awk '/^  /' | cut -d ' ' -f 3 )" -- $cur ) )
        ;;

        *)
          COMPREPLY=( $( compgen -W "$( 
NAMESPACE=''
OLD_IFS=$IFS

IFS=$'\n'
for line in $( $prev -T ); do
  if [ $line != 'Available tasks:' ]; then
    if [ ${line:0:2} == '  ' ]; then
      TASK=$(echo $line | awk -F ':' '{print $2;}' | cut -d ' ' -f 1)
      if [ -z $NAMESPACE ]; then
        echo $TASK
      else
        echo $NAMESPACE:$TASK
      fi
    else
      NAMESPACE=$line
    fi
  fi
done

IFS=$OLD_IFS
)" -- $cur ) )

          # Work-around bash_completion issue where bash interprets a colon as a separator.
          # Work-around borrowed from the darcs work-around for the same issue.
          local colonprefixes=${cur%"${cur##*:}"}
          local i=${#COMPREPLY[*]}
          while [ $((--i)) -ge 0 ]; do
            COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} 
          done
        ;;
      esac

      return 0
    ;;    

    *)
      case "$action" in
        "propel-generate-crud"|"propel-init-crud"|"propel-init-admin"|"propel:generate-crud"|"propel:init-admin")
          if (($COMP_CWORD == 3)); then
            COMPREPLY=( $( compgen -W "$( find lib/model -maxdepth 1 -name '*.php' -exec basename '{}' '.php' ';' | grep -v 'Peer$' | tr [:upper:] [:lower:] )" -- $cur ) )
          elif (($COMP_CWORD == 4)); then
            COMPREPLY=( $( compgen -W "$( find lib/model -maxdepth 1 -name '*.php' -exec basename '{}' '.php' ';' | grep -v 'Peer$' )" -- $cur ) )
          fi

          return 0
        ;;
      esac

      return 0
    ;;
  esac

  return 0  
}

complete -F _symfony symfony