[Bash-completion-devel] [PATCH 2/2] 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
Sun May 17 13:58:47 UTC 2015
---
completions/make | 9 ++++++++-
test/fixtures/make/Makefile | 16 ++++++++++++++++
test/lib/completions/make.exp | 27 +++++++++++++++++++++++++++
3 files changed, 51 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..25551a3 100644
--- a/test/lib/completions/make.exp
+++ b/test/lib/completions/make.exp
@@ -28,6 +28,33 @@ 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
+
+
+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
--
1.9.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20150517/d8858e7a/attachment.html>
More information about the Bash-completion-devel
mailing list