Last active
October 5, 2015 21:08
-
-
Save jaytaph/2876717 to your computer and use it in GitHub Desktop.
Console completion for Symfony2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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