diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-02 18:03:15 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-12-02 18:03:15 +1300 |
commit | 693fc13bb98b17938f2208fbadaec1996822fc5e (patch) | |
tree | 4a9cc6179f521528c663c8ab5f3bbc59dc57eaa0 /bash/bash_completion.d/make.bash | |
parent | Merge branch 'release/v2.6.0' (diff) | |
parent | Bump VERSION (diff) | |
download | dotfiles-693fc13bb98b17938f2208fbadaec1996822fc5e.tar.gz dotfiles-693fc13bb98b17938f2208fbadaec1996822fc5e.zip |
Merge branch 'release/v2.7.0'v2.7.0
* release/v2.7.0: (22 commits)
Bump VERSION
Make separate install-bash-completion target
Overhaul Bash completion scripts
Reduce ud() completion to just dirnames
Upgrade uncap_ex.vim plugin to v0.3.0
Apply syntax fixes to last _text_filenames specs
Rearrange _text_filenames completion a little
Remove prompt() completion
Throw away chgrp completion
Throw away Git Bash completion
Remove mysql(1) completion
Use consistent temp names for shell subfile vars
Overhaul pass(1) completion
Adjust syntax of two more completion loads
Remove ftp(1) completion
Remove `kill` completion
Use the positional parameter aliases for words
Overhaul bd() completion again
Remove unneeded -q option to shopt -s commands
Don't include dotfiles in keep() names
...
Diffstat (limited to 'bash/bash_completion.d/make.bash')
-rw-r--r-- | bash/bash_completion.d/make.bash | 93 |
1 files changed, 53 insertions, 40 deletions
diff --git a/bash/bash_completion.d/make.bash b/bash/bash_completion.d/make.bash index 0f39ef4b..2527d145 100644 --- a/bash/bash_completion.d/make.bash +++ b/bash/bash_completion.d/make.bash @@ -1,3 +1,8 @@ +# Load _completion_ignore_case helper function +if ! declare -F _completion_ignore_case >/dev/null ; then + source "$HOME"/.bash_completion.d/_completion_ignore_case.bash +fi + # Completion setup for Make, completing targets _make() { @@ -5,48 +10,56 @@ _make() { # first, then "Makefile"). You may want to add "GNU-makefile" after this. local mf for mf in makefile Makefile '' ; do - [[ -e $mf ]] || continue - break + ! [[ -e $mf ]] || break done [[ -n $mf ]] || return - # Iterate through the Makefile, line by line - local 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 -rd '' -a targets < \ - <(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 < "$mf" + # Iterate through completions produced by subshell + local ci comp + while read -r comp ; do + COMPREPLY[ci++]=$comp + done < <( + while IFS= read -r line ; do + + # Match expected format + case $line in + # Has no equals sign anywhere + (*=*) continue ;; + # First char not a tab + ($'\t'*) continue ;; + # Has a colon on the line + (*:*) ;; + # Skip anything else + (*) continue ;; + esac + + # Break the target up with space delimiters + local -a targets + IFS=' ' read -a targets -r \ + < <(printf '%s\n' "${line%%:*}") + + # Short-circuit if there are no targets + ((${#targets[@]})) || exit + + # Make matches behave correctly + if _completion_ignore_case ; then + shopt -s nocasematch 2>/dev/null + fi + + # Examine each target for completion suitability + local target + for target in "${targets[@]}" ; do + case $target in + # Not .PHONY, .POSIX etc + (.*) ;; + # Nothing with metacharacters + (*[^[:word:]./-]*) ;; + # Match! + ("$2"*) printf '%s\n' "$target" ;; + esac + done + + done < "$mf" + ) } complete -F _make -o bashdefault -o default make |