bash-completion: Fix spurious 'following' target completion candidate

The '--target' completion parsed 'cmake --build --target help'
with a sed pattern whose leading '...' matched any three
characters, so the header line yielded a bogus 'following'
candidate.  Anchor the pattern to literal dots.

Also note in the user-interaction guide that 'make' target
tab-completion is provided by the external bash-completion
package, which may hide the plain '<target>' name when a
'<target>/fast' variant exists, and recommend
'cmake --build --target' completion instead.

Fixes: #27873
This commit is contained in:
Daksh Mamodiya
2026-08-05 05:51:19 +02:00
parent a0d1a037ec
commit 0862819756
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ _cmake()
COMPREPLY=( $( compgen -W "$target_options" -- "$quoted" ) )
else
local targets=$( cmake --build "$build_dir" --target help 2>/dev/null \
| sed -n -e 's/^... \([^ ]*\).*$/\1/p' \
| sed -n -e 's/^\.\.\. \([^ ]*\).*$/\1/p' \
-e '/^\[/d' -e 's/^\([^ :]*\):.*$/\1/p' | \
grep -v '^/' | sort -u )
COMPREPLY=( $( compgen -W "$targets $target_options" -- "$quoted" ) )
+12
View File
@@ -618,6 +618,18 @@ are not rebuilt if out of date. The :ref:`Ninja Generators`
are sufficiently fast at dependency checking that
such targets are not provided for that generator.
.. note::
Shell tab-completion of ``make`` target names is provided
by the external ``bash-completion`` package, not by CMake.
Some versions of it hide the plain ``<target>`` name when a
``<target>/fast`` variant also exists, treating the ``/`` as
a directory separator. The targets themselves remain
available to build. To complete project target names
reliably, use :option:`--target <cmake--build --target>`
completion instead, e.g. tab-completion after
``cmake --build <dir> --target``.
:ref:`Makefile Generators` also provide build-targets to
preprocess, assemble and compile individual files in a
particular directory.