Last active
April 9, 2017 23:22
-
-
Save asentner/1a475f861f3f25c44fd1828c0b4c7df0 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
_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 --format=xml '.$command.' 2>/dev/null'); | |
$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 2>/dev/null | 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 | |
complete -F _console console.php | |
complete -F _console composer | |
complete -F _console terminus | |
complete -F _console artisan | |
complete -F _console appc | |
COMP_WORDBREAKS=${COMP_WORDBREAKS//:} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment