Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Last active October 5, 2015 21:08
Show Gist options
  • Save jaytaph/2876717 to your computer and use it in GitHub Desktop.
Save jaytaph/2876717 to your computer and use it in GitHub Desktop.
Console completion for Symfony2
#!/bin/sh
#
# Symfony2 App/Console autocompletion (commands and arguments only)
#
# Usable for both bash and zsh (probably)
#
# Usage:
# Load the script (or add to your .bashrc)
#
# source ./complete_console.sh
#
# Autocomplete:
#
# ./app/console <TAB>
#
# Will autocomplete both commands and its arguments.
#
if [[ -n ${ZSH_VERSION-} ]]; then
autoload -U +X bashcompinit && bashcompinit
fi
_complete_sf2_app_console() {
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
# Assume first word is the actual app/console command
console="${COMP_WORDS[0]}"
if [[ ${COMP_CWORD} == 1 ]] ; then
# No command found, return the list of available commands
cmds=` ${console} | sed -n -e '/^Available commands/,//p' | grep '^ ' | awk '{ print $1 }' `
else
# Commands found, parse options
cmds=` ${console} ${COMP_WORDS[1]} --help | sed -n -e '/^Options/,/^$/p' | grep '^ ' | awk '{ print $1 }' `
fi
COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
return 0
}
export COMP_WORDBREAKS="\ \"\\'><=;|&("
complete -F _complete_sf2_app_console console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment