formatted grunt completion and used helper function

pull/1782/head
Gurkirat Singh 2021-01-10 19:24:26 +05:30
parent f790ba2659
commit 475393c6b7
No known key found for this signature in database
GPG Key ID: CFD64E1DCB3DA835
1 changed files with 34 additions and 30 deletions

View File

@ -41,10 +41,13 @@
# eval "$(grunt --completion=bash)" # eval "$(grunt --completion=bash)"
# Search the current directory and all parent directories for a gruntfile. # Search the current directory and all parent directories for a gruntfile.
function _grunt_gruntfile() {
if _command_exists grunt
then
function _grunt_gruntfile() {
local curpath="$PWD" local curpath="$PWD"
while [[ "$curpath" ]]; do while [[ "$curpath" ]]; do
for gruntfile in "$curpath/"{G,g}runtfile.{js,coffee}; do for gruntfile in "$curpath/"{G,g}runtfile{.js,.coffee,}; do
if [[ -e "$gruntfile" ]]; then if [[ -e "$gruntfile" ]]; then
echo "$gruntfile" echo "$gruntfile"
return return
@ -53,10 +56,10 @@ function _grunt_gruntfile() {
curpath="${curpath%/*}" curpath="${curpath%/*}"
done done
return 1 return 1
} }
# Enable bash autocompletion. # Enable bash autocompletion.
function _grunt_completions() { function _grunt_completions() {
# The currently-being-completed word. # The currently-being-completed word.
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
# The current gruntfile, if it exists. # The current gruntfile, if it exists.
@ -70,6 +73,7 @@ function _grunt_completions() {
[[ "$cur" == -* ]] && compls="$compls $opts" [[ "$cur" == -* ]] && compls="$compls $opts"
# Tell complete what stuff to show. # Tell complete what stuff to show.
COMPREPLY=($(compgen -W "$compls" -- "$cur")) COMPREPLY=($(compgen -W "$compls" -- "$cur"))
} }
complete -o default -F _grunt_completions grunt complete -o default -F _grunt_completions grunt
fi