From 9d97532f8ee6a60f8ff7cc0db65c4fcabc047bb8 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Fri, 21 Feb 2020 12:56:00 -0600 Subject: [PATCH] enhance makefile completion and make shellcheck happy --- completion/available/makefile.completion.bash | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/completion/available/makefile.completion.bash b/completion/available/makefile.completion.bash index 9f70958a..d53e18fb 100644 --- a/completion/available/makefile.completion.bash +++ b/completion/available/makefile.completion.bash @@ -5,18 +5,24 @@ _makecomplete() { # https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html - local files=( $(find . -maxdepth 1 -regextype posix-extended -regex '.*(GNU)?[Mm]akefile$' -printf '%f ') ) + local files=() + while IFS='' read -r line; do + files+=("$line") + done < <(find . -maxdepth 1 -regextype posix-extended -regex '.*(GNU)?[Mm]akefile$' -printf '%f\n') # collect all targets - local targets='' - for f in ${files[@]} ; do - for t in $(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' $f | cut -d':' -f1) ; do - targets+="$t\n" - done + local targets=() + for f in "${files[@]}" ; do + while IFS='' read -r line ; do + targets+=("$line") + done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) done # flatten the array for completion - COMPREPLY=($(compgen -W "$(echo -e "$targets" | head -c -1 | sort -u)" -- ${COMP_WORDS[COMP_CWORD]})) + COMPREPLY=() + while IFS='' read -r line ; do + COMPREPLY+=("$line") + done < <(compgen -W "$(tr ' ' '\n' <<<"${targets[@]}" | sort -u)" -- "${COMP_WORDS[COMP_CWORD]}") return 0 }