Created
October 2, 2023 18:37
-
-
Save danielnegri/0d1b598b669719e099c088e673136030 to your computer and use it in GitHub Desktop.
Makefile Autocomplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile Auto-complete | |
function _makefile_targets { | |
local curr_arg; | |
local targets; | |
# Find makefile targets available in the current directory | |
targets='' | |
if [[ -e "$(pwd)/Makefile" ]]; then | |
targets=$( \ | |
grep -oE '^[a-zA-Z0-9_-]+:' Makefile \ | |
| sed 's/://' \ | |
| tr '\n' ' ' \ | |
) | |
fi | |
# Filter targets based on user input to the bash completion | |
curr_arg=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "${targets[@]}" -- $curr_arg ) ); | |
} | |
complete -F _makefile_targets make |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment