Skip to content

Instantly share code, notes, and snippets.

@bastman
Created October 9, 2018 12:11
Show Gist options
  • Save bastman/87b6f5cc018da63e446ba25d72a79fb0 to your computer and use it in GitHub Desktop.
Save bastman/87b6f5cc018da63e446ba25d72a79fb0 to your computer and use it in GitHub Desktop.
bash_profile: make autocomplete
# .bashrc: see: https://stackoverflow.com/questions/33760647/makefile-autocompletion-on-mac
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