Created
August 8, 2016 08:35
-
-
Save ignasbernotas/dd72aa009c4828b10e4b2ad88e00c24f to your computer and use it in GitHub Desktop.
Artisan bash autocompletion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
_artisan() | |
{ | |
local cache commands artisanOutput word | |
_get_comp_words_by_ref -n : -c word | |
cache=/tmp/.artisan_command_cache_$BASHPID | |
commands=() | |
# enables cache per terminal session | |
# calling artisan is too time consuming for each tab press | |
if [ -f $cache ]; | |
then | |
commands=$(cat "$cache") | |
else | |
commands=$(php artisan list --raw | cut -f 1 -d " " | tr "\n" " ") | |
printf "%s\n" "${commands[@]}" > "$cache" | |
fi | |
COMPREPLY=( $(compgen -W "${commands}" -- $word) ) | |
# remove color from the word breaking list | |
__ltrim_colon_completions "$word" | |
return 0 | |
} | |
complete -F _artisan artisan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment