[Bash-completion-commits] [bash-completion] 01/01: make: Offer hidden targets when it is clear that the user is trying to complete one of them

Ville Skyttä scop-guest at moszumanska.debian.org
Sat Sep 5 05:44:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

scop-guest pushed a commit to branch master
in repository bash-completion.

commit e0c08321795c8174fa2275d2683c4ffc1b36db5b
Author: Tristan Wibberley <tristan.wibberley at gmail.com>
Date:   Fri Sep 4 21:56:06 2015 +0100

    make: Offer hidden targets when it is clear that the user is trying to complete one of them
    
    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..44abcbb 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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/bash-completion/bash-completion.git



More information about the Bash-completion-commits mailing list