zsh-users
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Simple make completion that just works
Date: Tue, 2 Aug 2022 19:54:56 -0500	[thread overview]
Message-ID: <CAMP44s2vRKWzy_c-juYJ21Z=NxMQ124aNbA3eL+tkrL4NpeAHQ@mail.gmail.com> (raw)

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


                 reply	other threads:[~2022-08-03  0:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMP44s2vRKWzy_c-juYJ21Z=NxMQ124aNbA3eL+tkrL4NpeAHQ@mail.gmail.com' \
    --to=felipe.contreras@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).