diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2014-03-02 01:49:20 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2014-03-02 01:49:20 +1300 |
commit | 4d244d69ed75ebfb6f3309459acb729ee060d9c0 (patch) | |
tree | 1fb5a3872a79eb8cf146218f239f7628e4948475 /bash/bashrc.d | |
parent | Add install target for rxvt-unicode tools (diff) | |
download | dotfiles-4d244d69ed75ebfb6f3309459acb729ee060d9c0.tar.gz dotfiles-4d244d69ed75ebfb6f3309459acb729ee060d9c0.zip |
Basic target completion for make(1)
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/make.bash | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/bash/bashrc.d/make.bash b/bash/bashrc.d/make.bash new file mode 100644 index 00000000..d6f4eafa --- /dev/null +++ b/bash/bashrc.d/make.bash @@ -0,0 +1,37 @@ +# Bail if no make(1) +if ! hash make 2>/dev/null ; then + return +fi + +# Completion setup for Make, completing targets +# +# Note that because of the +_make() { + local word=${COMP_WORDS[COMP_CWORD]} + + # Quietly bail if no legible Makefile + if [[ ! -r Makefile ]] ; then + return 1 + fi + + # Build a list of targets by parsing the Makefile + local -a targets tokens + local target line + while read -r line ; do + if [[ $line == *:* ]] ; then + target=$line + target=${target%%:*} + target=${target% } + if [[ $target != *[^[:alnum:][:space:]_-]* ]] ; then + IFS=' ' read -a tokens \ + < <(printf '%s\n' "$target") + targets=("${targets[@]}" "${tokens[@]}") + fi + fi + done < Makefile + + # Complete with matching targets + COMPREPLY=( $(compgen -W "${targets[*]}" -- "$word") ) +} +complete -F _make -o default make + |