Skip to content

Instantly share code, notes, and snippets.

@gonzalo-bulnes
Created January 10, 2017 09:49
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 gonzalo-bulnes/a05aac06770441d02a5fc9d5df4802ce to your computer and use it in GitHub Desktop.
Save gonzalo-bulnes/a05aac06770441d02a5fc9d5df4802ce to your computer and use it in GitHub Desktop.
# Provide autocompletion for a Makefile targets.
#
# Usage:
# source .bash_completion # this file
# make[tab] # autocompletes the .PHONY targets :)
#
# See https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2
_make()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# autocomplete all the .PHONY targets, improvements are welcome!
opts=$(cat Makefile | grep PHONY | awk '{$1=""; print $0;}')
if [[ ${cur} == * ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -F _make make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment