Skip to content

Commit 93121e6

Browse files
committed
Add instructions to enable bash completion of Makefile targets
1 parent d998926 commit 93121e6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tools/make/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,31 @@ To check licenses of installed package dependencies,
459459
$ make check-licenses
460460
```
461461

462+
---
463+
464+
#### Bash Completion
465+
466+
To enable [bash completion][bash-completion] of Makefile targets, add
467+
468+
```
469+
complete -W "\`find . ! \( -path \"*/node_modules/*\" -prune \) -and \( -name 'Makefile' -o -name '*.mk' \) | xargs grep '^.PHONY: ' | awk '{print $2}'\`" make
470+
```
471+
472+
to your `~/.bash_profile` or `~/.bashrc`. Note that completion is __not__ exhaustive, as the above only includes targets which have been __explicitly__ declared phony targets
473+
474+
```
475+
.PHONY: beep-boop
476+
```
477+
478+
and does not include targets declared via variables. Excluded targets could be included by dumping the Makefile database `make -qp`, but such inclusion has a performance cost and is unnecessary due to the predominant use of `PHONY`.
479+
462480
463481
<!-- <links> -->
464482
465483
[make]: https://www.gnu.org/software/make/manual/make.html#Introduction
466484
[jsdoc]: http://usejsdoc.org/
467485
[nvm]: https://github.com/creationix/nvm
486+
[bash-completion]: https://www.gnu.org/software/bash/manual/bashref.html#Programmable-Completion
468487
469488
<!-- </links> -->
470489

0 commit comments

Comments
 (0)