Skip to content

Instantly share code, notes, and snippets.

@aik099
Created May 12, 2015 11:15
Show Gist options
  • Save aik099/1a72ab19beb3038fbb3e to your computer and use it in GitHub Desktop.
Save aik099/1a72ab19beb3038fbb3e to your computer and use it in GitHub Desktop.
Symfony application directory-agnostic completion script
#!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]}"
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 app jira-cli jira-cli.phar box.phar artisan composer
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment