Bash – Hide make targets from shell when users autocomplete in bash

autocompletebashmake

Is there a way to flag some targets in a Makefile so that they don't appear at all in the shell when the user types make and then presses Tab ?
I am having a Makefile with too many recipes and I don't want them all to appear in the shell autocompletion when a users presses Tab looking for targets.

Best Answer

After studying the problem and coming up with a solution that I wrote in the first answer, I realized that there is another very simple way.

Just start the target's names you don't want to show beginning with a dot.

Example:

.PHONY: foo .hiddentarget
foo: foo.x .hiddentarget
foo.x: foo.c
        touch foo.x
.hiddentarget: foo.x
        echo foo.x ok, I believe

And that's all you need!

I came to this idea after trying to figure out how to prevent a target named .HIDDENGOALS being called by mistake and run all hidden goals. :)

Warning Although I don't see any, I'm not sure if there isn't any side effect on using target names like this ".targetname" (starting with a dot).

Related Question