zsh-users
 help / color / mirror / code / Atom feed
* Simple make completion that just works
@ 2022-08-03  0:54 Felipe Contreras
  0 siblings, 0 replies; only message in thread
From: Felipe Contreras @ 2022-08-03  0:54 UTC (permalink / raw)
  To: Zsh Users

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-03  0:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03  0:54 Simple make completion that just works Felipe Contreras

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).