diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 01:17:09 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 02:09:30 +1200 |
commit | 4cbbd121c012b3962f12fdff0f1820c3b8636a44 (patch) | |
tree | 00149270df365ed0b7a1b9e9f4922fe7d5a80eb3 /bash/bash_completion.d/make.bash | |
parent | Change ca from Bash func to sh script (diff) | |
download | dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.tar.gz dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.zip |
Move bash completion setup into separate dir
Diffstat (limited to 'bash/bash_completion.d/make.bash')
-rw-r--r-- | bash/bash_completion.d/make.bash | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bash/bash_completion.d/make.bash b/bash/bash_completion.d/make.bash new file mode 100644 index 00000000..ca209e8e --- /dev/null +++ b/bash/bash_completion.d/make.bash @@ -0,0 +1,44 @@ +# Completion setup for Make, completing targets +_make() { + + # Bail if no legible Makefile + [[ -r Makefile ]] || return 1 + + # Iterate through the Makefile, line by line + while IFS= read -r line ; do + case $line in + + # We're looking for targets but not variable assignments + $'\t'*) ;; + *:=*) ;; + *:*) + + # Break the target up with space delimiters + local -a targets + IFS=' ' read -a targets -d '' < \ + <(printf '%s\0' "${line%%:*}") + + # Iterate through the targets and add suitable ones + local target + for target in "${targets[@]}" ; do + case $target in + + # Don't complete special targets beginning with a + # period + .*) ;; + + # Don't complete targets with names that have + # characters outside of the POSIX spec (plus slashes) + *[^[:word:]./-]*) ;; + + # Add targets that match what we're completing + ${COMP_WORDS[COMP_CWORD]}*) + COMPREPLY[${#COMPREPLY[@]}]=$target + ;; + esac + done + ;; + esac + done < Makefile +} +complete -F _make -o default make |