Skip to content

Instantly share code, notes, and snippets.

@Zhwt
Forked from jhoff/README.md
Last active April 10, 2020 10:38
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 Zhwt/6dd6796cd196aa1d457b217ba655c5f4 to your computer and use it in GitHub Desktop.
Save Zhwt/6dd6796cd196aa1d457b217ba655c5f4 to your computer and use it in GitHub Desktop.
Bash-only Laravel Artisan tab auto-complete

This version uses a little cache mechanic to reduce waiting time between pressing tabs.

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_COMMANDS=`php artisan --raw --no-ansi list | sed "s/[[:space:]].*//g"`
_artisan()
{
	COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
	COMPREPLY=(`compgen -W "$ARTISAN_COMMANDS" -- "${COMP_WORDS[COMP_CWORD]}"`)
	return 0
}
complete -F _artisan artisan
alias artisan='php artisan'

In case you got:

stdout is not a tty

errors on Windows git-bash or similar, change the ARTISAN_COMMANDS= line to:

ARTISAN_COMMANDS=`php.exe artisan --raw --no-ansi list | sed "s/[[:space:]].*//g"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment