Skip to content

Instantly share code, notes, and snippets.

@ignasbernotas
Created August 8, 2016 08:35
Show Gist options
  • Save ignasbernotas/dd72aa009c4828b10e4b2ad88e00c24f to your computer and use it in GitHub Desktop.
Save ignasbernotas/dd72aa009c4828b10e4b2ad88e00c24f to your computer and use it in GitHub Desktop.
Artisan bash autocompletion
#!/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