Skip to content

Instantly share code, notes, and snippets.

@matt-allan
Last active May 12, 2017 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matt-allan/c75b577981ab78906b69477359aeef16 to your computer and use it in GitHub Desktop.
Save matt-allan/c75b577981ab78906b69477359aeef16 to your computer and use it in GitHub Desktop.
_composer_scripts() {
local cur="${COMP_WORDS[COMP_CWORD]}"
local scripts=$(composer run-script -l --no-ansi 2> /dev/null | awk '/^ +[a-z]+/ { print $1 }')
COMPREPLY=( $(compgen -W "${scripts}" -- ${cur}) )
return 0
}
complete -F _composer_scripts composer
@matt-allan
Copy link
Author

This requires a newer version of bash completion but works correctly when the script name contains : i.e. test:unit:

_composer_scripts() {
    local cur
    _get_comp_words_by_ref -n : cur
    local scripts=$(composer run-script -l --no-ansi 2> /dev/null |  awk '/^ +[a-z]+/ { print $1 }')
    COMPREPLY=( $(compgen -W "${scripts}" -- ${cur}) )
    __ltrim_colon_completions "$cur"
    return 0
}

complete -F _composer_scripts composer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment