From c8f69a1dc8dadb6a772da1bb3855ec83a4f59c52 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 6 Jul 2021 00:32:47 +0900 Subject: [PATCH 1/4] refactor(make): Use awk to extract target names --- completions/make | 175 ++++++++++++++++++++++++----------------------- 1 file changed, 88 insertions(+), 87 deletions(-) diff --git a/completions/make b/completions/make index 5952bd5e3ca..85978a38d44 100644 --- a/completions/make +++ b/completions/make @@ -1,91 +1,92 @@ # bash completion for GNU make -*- shell-script -*- -# TODO: rename per API conventions, rework to use vars rather than outputting(?) -_make_target_extract_script() +# Extract the valid target names starting with PREFIX from the output of +# `make -npq' +# @param mode If this is `-d', the directory names already specified in +# PREFIX are omitted in the output +# @param prefix Prefix of the target names +_comp_cmd_make__extract_targets() { - local mode="$1" - shift - - local prefix="$1" - local prefix_pat=$(command sed 's/[][\,.*^$(){}?+|/]/\\&/g' <<<"$prefix") - local basename=${prefix##*/} - local dirname_len=$((${#prefix} - ${#basename})) - # Avoid expressions like '\(.\{0\}\)', FreeBSD sed doesn't like them: - # > sed: 1: ...: RE error: empty (sub)expression - local dirname_re= - ((dirname_len > 0)) && dirname_re="\(.\{${dirname_len}\}\)" - - if [[ ! $dirname_re ]]; then - local output="\1" - elif [[ $mode == -d ]]; then - # display mode, only output current path component to the next slash - local output="\2" - else - # completion mode, output full path to the next slash - local output="\1\2" - fi - - cat <