diff --git a/completion/available/artisan.completion.bash b/completion/available/artisan.completion.bash new file mode 100644 index 0000000000..9981e877e3 --- /dev/null +++ b/completion/available/artisan.completion.bash @@ -0,0 +1,26 @@ +# shellcheck shell=bash +cite "about-completion" +about-completion "Laravel artisan completion" + +# Completion function for Laravel artisan +_artisan_completion() { + local cur commands + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + + # Only provide completions if artisan file exists in current directory + if [[ ! -f "artisan" ]]; then + return 0 + fi + + # Get list of available artisan commands + # Use command prefix to bypass user aliases + commands=$(command php artisan --raw --no-ansi list 2> /dev/null | command sed "s/[[:space:]].*//") + + # shellcheck disable=SC2034,SC2207 + COMPREPLY=($(compgen -W '${commands}' -- "${cur}")) + return 0 +} + +# Complete for both 'artisan' and common alias 'art' +complete -F _artisan_completion artisan art