[Bash-completion-devel] [PATCH] make: Offer hidden targets when it is clear that the user is trying to complete one of them

Tristan Wibberley tristan.wibberley at gmail.com
Fri Sep 4 20:56:06 UTC 2015


Please apply the patch below for "make" completion.

It adds support for completing hidden targets when the user has partially
completed it.

My previous trouble with the unit test is resolved - it is due to my
support for display-mode completion which requires an extra option in the
test case assertion:

   -expect-cmd-minus "."

---
 completions/make              |  9 ++++++++-
 test/fixtures/make/Makefile   | 16 ++++++++++++++++
 test/lib/completions/make.exp | 28 ++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/completions/make b/completions/make
index 3f697be..e84e5ba 100644
--- a/completions/make
+++ b/completions/make
@@ -61,9 +61,16 @@ function _make_target_extract_script()
       /^\.POSIX:/                 d;            # special target
       /^\.NOEXPORT:/              d;            # special target
       /^\.MAKE:/                  d;            # special target
+EOF

-      /^[^a-zA-Z0-9]/             d;            # convention for hidden tgt
+    # don't complete with hidden targets unless we are doing a partial
completion
+    if [[ -z "${prefix_pat}" || "${prefix_pat}" = */ ]]; then
+      cat <<EOF
+      /^${prefix_pat}[^a-zA-Z0-9]/d             # convention for hidden tgt
+EOF
+    fi

+    cat <<EOF
       h;                                        # hold target
       d;                                        # delete line
     }
diff --git a/test/fixtures/make/Makefile b/test/fixtures/make/Makefile
index 1a59f21..3d1d5f3 100644
--- a/test/fixtures/make/Makefile
+++ b/test/fixtures/make/Makefile
@@ -20,6 +20,22 @@ install: all
 clean:
  -rm -f $(NAME)

+.test_passes:
+ ./sample >/dev/null
+ touch ^@
+
+.cache/.1:
+ touch $@
+
+.cache/.2:
+ touch $@
+
+.cache/1:
+ touch $@
+
+.cache/2:
+ touch $@
+
 ifndef __BASH_MAKE_COMPLETION__
 -include sample.d
 endif
diff --git a/test/lib/completions/make.exp b/test/lib/completions/make.exp
index 977485d..93a53db 100644
--- a/test/lib/completions/make.exp
+++ b/test/lib/completions/make.exp
@@ -28,6 +28,34 @@ assert_complete_dir $targets "make " $dir $test
 sync_after_int


+set test "\"make .<TAB>\" should complete hidden targets"
+set dir $::srcdir/fixtures/make
+set targets ".test_passes .cache/"
+assert_complete_dir $targets "make ." $dir $test
+
+
+sync_after_int
+
+
+set test "\"make .cache/<TAB>\" should complete targets"
+set dir $::srcdir/fixtures/make
+set targets "1 2"
+assert_complete_dir $targets "make .cache/" $dir $test
+
+
+sync_after_int
+
+
+set test "\"make .cache/.<TAB>\" should complete hidden targets"
+set dir $::srcdir/fixtures/make
+set targets ".1 .2"
+assert_complete_dir $targets "make .cache/." $dir $test \
+ -expect-cmd-minus "."
+
+
+sync_after_int
+
+
 set test "\"make <TAB>\" should not show anything in directory without
makefile"
 set dir $::srcdir/fixtures/make/empty_dir
 assert_complete_dir "" "make " $dir $test
-- 
2.5.0


On 27 April 2015 at 00:41, Tristan Wibberley <tristan.wibberley at gmail.com>
wrote:

> Resending with a useful subject line
>
> On 20 April 2015 at 13:00, <
> bash-completion-devel-request at lists.alioth.debian.org> wrote:
>
> [snipped digest mail]
>
>> Date: Sun, 19 Apr 2015 16:05:30 +0300
>> From: Ville Skytt? <ville.skytta at iki.fi>
>> Message-ID:
>>         <
>> CABr9L5ADihGZEx08Qp3OBhCuP0CPyuJ2yHUyMJ0Ze0U2+dN9tg at mail.gmail.com>
>>
>
>
>
>> On Sun, Apr 5, 2015 at 5:31 PM, Tristan Wibberley
>> <tristan.wibberley at gmail.com> wrote:
>>
>> > Secondly, please would you have a look at the bundle and consider
>> applying
>> > it?.
>>
>> I started looking into it. For me this is the first time I've come
>> across git bundles and I must say that for contributions like this I
>> find the format-patch/send-email approach which is documented in our
>> README *much* preferrable. Could you please follow that in the future?
>>
>
> Certainly, it was also the first time I used git bundles so I thought I'd
> try it out. I didn't  know about the README's requirements because I first
> found the mailing list via google.
>
>
> Anyway, about the first commit. I looked into what make produces off
>> the modified Makefile, but it did not add any whitespace to any "#
>> Files" or "# Not a target" lines, but I do see more than one space in
>> the "# File is an intermediate prerequisite" line.
>
>
>
> Could you clarify
>> what the two first modifications are for, i.e. do you have a case
>> where make produces output that would require these adjustments?
>>
>
> As I recall, nothing requires the modifications to the match for '# Files'
> and '# Not a target' except for good practice. Since the output in Ubuntu
> changed in way that nonobviously broke completion I thought that I would
> make the script robust to the wider class of format changes so that those
> features don't vanish - unnoticed - if somebody unifies the output of make.
> Ie, I applied the network rule based on this experience.
>
>
> The variable patch seems innocent enough, I've applied it.
>>
>
> Great, thanks.
>
>
> Any thoughts on the problem with the test case for the hidden target
> completion?
>
>
> Thanks
> --
> Tristan
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20150904/abab6eb2/attachment.html>


More information about the Bash-completion-devel mailing list