aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-06-24 17:44:58 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-06-24 17:44:58 +1200
commit9e6686fab7efe11e473f394cdee842d6ea4a886e (patch)
tree9b1ecfc342ebfd455d3d4acfaae9b980d52e4bb2 /bash/bashrc.d
parentAdd kvlt(6) (diff)
downloaddotfiles-9e6686fab7efe11e473f394cdee842d6ea4a886e.tar.gz
dotfiles-9e6686fab7efe11e473f394cdee842d6ea4a886e.zip
More efficient/terser make(1) completion
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/make.bash50
1 files changed, 29 insertions, 21 deletions
diff --git a/bash/bashrc.d/make.bash b/bash/bashrc.d/make.bash
index 2359d125..094e9657 100644
--- a/bash/bashrc.d/make.bash
+++ b/bash/bashrc.d/make.bash
@@ -4,27 +4,35 @@ _make() {
# Bail if no legible Makefile
[[ -r Makefile ]] || return 1
- # Build a list of targets by parsing the Makefile
- local -a targets tokens
- local line target token
- while read -r line ; do
- if [[ $line == *:* && $line != *:=* ]] ; then
- target=$line
- target=${target%%:*}
- target=${target% }
- [[ $target != *[^[:alnum:][:space:]_-]* ]] || continue
- IFS=' ' read -a tokens \
- < <(printf '%s\n' "$target")
- for token in "${tokens[@]}" ; do
- targets[${#targets[@]}]=$token
- done
- fi
- done < Makefile
+ # 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
+ while IFS= read -d ' ' -r target ; do
+ case $target in
- # Complete with matching targets
- for target in "${targets[@]}" ; do
- [[ $target == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
- COMPREPLY[${#COMPREPLY[@]}]=$target
- done
+ # 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 < <(printf '%s' "${line%%:*}")
+ ;;
+ esac
+ done < Makefile
}
complete -F _make -o default make