Skip to content

Instantly share code, notes, and snippets.

@nils-werner
Last active December 17, 2015 12:59
Show Gist options
  • Save nils-werner/5613468 to your computer and use it in GitHub Desktop.
Save nils-werner/5613468 to your computer and use it in GitHub Desktop.
Autocompletion for Composer and Artisan
# Put this either in
#
# 1. a new file called ~/.bash_completion
# 2. your ~/.bashrc
#
_composer()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local cmd=${COMP_WORDS[0]}
if ($cmd > /dev/null 2>&1)
then
COMPREPLY=( $(compgen -W "$($cmd list --raw | cut -f 1 -d " " | tr "\n" " ")" -- $cur) )
fi
}
complete -F _composer composer
complete -F _composer composer.phar
_artisan()
{
local cur
_get_comp_words_by_ref -n : cur
if( [ ${COMP_WORDS[0]} = "artisan" ] || [ ${COMP_WORDS[0]} = "./artisan" ] || ( [ ${COMP_WORDS[0]} == "php" ] && [ ${COMP_WORDS[1]} = "artisan" ] ) )
then
if (php artisan > /dev/null 2>&1)
then
COMPREPLY=( $(compgen -W "$(php artisan list --raw | cut -f 1 -d " " | tr "\n" " ")" -- $cur) )
__ltrim_colon_completions "$cur"
fi
fi
}
complete -F _artisan php
complete -F _artisan artisan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment