From fff320b56ba42964033089809c77b38147058598 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 23 Aug 2023 21:42:54 +0000 Subject: [PATCH] completions: make: respect line continuations in recipes Without this, a recipe containing a trailing backslash followed by a line not beginning with tab (like any non-continued recipe lines would) would result in the continuation showing up in completions. Whenever a line ends in a backslash, consider the next line invalid as a target. Regex explanation: ^([^#]*[^#\\])? -- optional prefix not containing comment character and not ending in backslash (\\\\)*\\$ -- 2n+1 backslashes at end of line (handles escaped backslashes) --- share/completions/make.fish | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/share/completions/make.fish b/share/completions/make.fish index 2f5f42f3e..6dec6289d 100644 --- a/share/completions/make.fish +++ b/share/completions/make.fish @@ -12,9 +12,13 @@ function __fish_print_make_targets --argument-names directory file if make --version 2>/dev/null | string match -q 'GNU*' # https://stackoverflow.com/a/26339924 make $makeflags -pRrq : 2>/dev/null | - awk -F: '/^# Files/,/^# Finished Make data base/ { + awk -F: -v 'bs_regex=\\\\\\\\' '/^# Files/,/^# Finished Make data base/ { if ($1 == "# Not a target") skip = 1; - if ($1 !~ "^[#.\t]") { if (!skip) print $1; skip=0 } + if ($1 !~ "^[#.\t]" && !is_continuation ) { + if (!skip) print $1; + skip = 0 + } + is_continuation = $0 ~ "^([^#]*[^#" bs_regex "])?(" bs_regex bs_regex ")*" bs_regex "$"; }' 2>/dev/null else # BSD make