Skip to content

Instantly share code, notes, and snippets.

@tommyvdv
Last active March 8, 2019 07:45
Show Gist options
  • Save tommyvdv/7aa4ca917d26f589ab7766b076493723 to your computer and use it in GitHub Desktop.
Save tommyvdv/7aa4ca917d26f589ab7766b076493723 to your computer and use it in GitHub Desktop.
Make(file) completion
# List make targets since this is not something make can do the way we want it to
list_make_targets() {
file=Makefile && [[ -f "$file" ]] && grep -oE '^[a-zA-Z0-9_.-]+:([^=]|$)' "$file" | sed 's/[^a-zA-Z0-9_.-]*$//' || printf '"%s" not found\n' "$file"
}
# Tell (ba)sh completion to use function "list_make_targets" for completion
make_load_autocomplete() {
complete -W "\`list_make_targets\`" make
}
# Add an alias because we can
alias listmake=list_make_targets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment