Skip to content

Instantly share code, notes, and snippets.

@danielnegri
Created October 2, 2023 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielnegri/0d1b598b669719e099c088e673136030 to your computer and use it in GitHub Desktop.
Save danielnegri/0d1b598b669719e099c088e673136030 to your computer and use it in GitHub Desktop.
Makefile Autocomplete
# 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