Skip to content

Instantly share code, notes, and snippets.

@ericpardee
Created August 3, 2024 18:03
Show Gist options
  • Save ericpardee/cd6dbcad17a8d269c34a3a0772f424cc to your computer and use it in GitHub Desktop.
Save ericpardee/cd6dbcad17a8d269c34a3a0772f424cc to your computer and use it in GitHub Desktop.
# Define make completions
function _make_completions() {
local -a targets
if [[ -f 'Makefile' ]]; then
# Read targets from Makefile using Extended Regular Expressions
# This regex aims to match any target that does not start with a dot and includes more characters than before.
targets=($(grep -oE '^[^\.#][^ ]*:' Makefile | sed 's/:.*//'))
fi
# Define completions based on targets
_describe 'target' targets
}
# Tell Zsh to use this function for make completion
compdef _make_completions make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment