If you are an Oh-my-zsh user, see the Laravel 5 plugin
For the rest of us Bash users, all of the Laravel Artisan autocomplete solutions out there require installing a composer package to get a list of artisan commands. Turns out this isn't really necessary. Simply add the provided code in ~/.bash_profile ( or similarly sourced file ) and you'll get artisan command tab completes on any project on your system.
_artisan()
{
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
COMMANDS=`php artisan --raw --no-ansi list | sed "s/[[:space:]].*//g"`
COMPREPLY=(`compgen -W "$COMMANDS" -- "${COMP_WORDS[COMP_CWORD]}"`)
return 0
}
complete -F _artisan art
complete -F _artisan artisan
Hey thanks for this. I really like the fact that it works completely in the shell without needing a package to be installed. I'm a fussy bastard and felt the delay on auto-complete was a bit too slow (understandable because each time you ask the shell to do an auto-complete it is firing up a new instance of
artisan list
). So, as an interim solution, I define an extra shell function to create a cache file with all the artisan commands, and then simplycat
this file for auto-complete. It does require that extra step of calling the cache function, but my commands don't change that much. If the cache file doesn't exist, then I fallback to theartisan list
approach.So to create the command cache file:
and to remove the cache file