Skip to content

Instantly share code, notes, and snippets.

@faboo03
Created June 5, 2015 09:43
Show Gist options
  • Save faboo03/f8b04cf6633913cd51e8 to your computer and use it in GitHub Desktop.
Save faboo03/f8b04cf6633913cd51e8 to your computer and use it in GitHub Desktop.
Add autocomplete for SF2 Console

Installation

Add console to your path and copy the file console_autocomplete.sh to /home/$USER and add it to source

then run this

echo 'PATH="./app:./bin:$PATH"' >> ~/.bash_aliases
echo . ~/.console_autocomplete >> ~/.bash_aliases
#!/bin/bash
#
# bash completion support for symfony2 console
#
# Copyright (C) 2011 Matthieu Bontemps <matthieu@knplabs.com>
# Distributed under the GNU General Public License, version 2.0.
_console()
{
local cur prev script
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
script="${COMP_WORDS[0]}"
te
if [[ ${cur} == -* ]] ; then
PHP=$(cat <<'HEREDOC'
array_shift($argv);
$script = array_shift($argv);
$command = '';
foreach ($argv as $v) {
if (0 !== strpos($v, '-')) {
$command = $v;
break;
}
}
$xmlHelp = shell_exec($script.' help --xml '.$command);
$options = array();
if (!$xml = @simplexml_load_string($xmlHelp)) {
exit(0);
}
foreach ($xml->xpath('/command/options/option') as $option) {
$options[] = (string) $option['name'];
}
echo implode(' ', $options);
HEREDOC
)
args=$(printf "%s " "${COMP_WORDS[@]}")
options=$($(which php) -r "$PHP" ${args});
COMPREPLY=($(compgen -W "${options}" -- ${cur}))
return 0
fi
commands=$(${script} list --raw | sed -E 's/(([^ ]+ )).*/\1/')
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0;
}
complete -F _console console
complete -F _console console-dev
complete -F _console console-test
complete -F _console console-prod
complete -F _console console-staging
complete -F _console Symfony
complete -F _console sf
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment