Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Simple make completion that just works



Hi,

A long time ago I had a problem with the completion of the make
command that made me write a hack to workaround it. I've been using
that hack for several years (maybe a decade), and it turns out it
works perfectly fine and I don't need anything else.

I decided to clean it up, and the result is rather clean, so I've
decided to share it.

Unlike the official completion this uses the make command to generate
the list of targets and *only* completes those targets. It's possible
to configure the official completion to use the make command, but it's
buggy, slow, and then it will complete all the files, regardless of
whether or not they are in the Makefile.

Sure, my little script doesn't show any options or help, but I don't
need them, all I want is 'make <tab>' to work quickly and correctly.

You might find it useful too.

Cheers.

#compdef make

_make_parse () {
  awk -v RS= -F: -v PRX="$1" '!match($1, "^" PFX) { next } $1 ~
/^[^#%]+$/ { print $1 }'
}

local -a targets cmd=(${words[1,CURRENT-1]})
local cur=$words[CURRENT] prev=$words[CURRENT-1]
local ret=1

if [[ "$prev" == -[CI] ]]; then
  _files -/ && ret=0
else
  targets=($($cmd -npq : 2> /dev/null | _make_parse "$cur"))
  _multi_parts -f -- / targets && ret=0
fi

return ret

-- 
Felipe Contreras




Messages sorted by: Reverse Date, Date, Thread, Author