From a1380a736b7d776b048225d475225ce6c2d515d9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 15 Mar 2019 19:50:28 +0100 Subject: [PATCH] Move __fish_print_make_targets into make completions A function file for a function used only by one completion (and unlikely to be used anywhere else). If another user shows up, we can move it out again. Part of #5279 [ci skip] --- share/completions/make.fish | 33 +++++++++++++++++++ .../functions/__fish_print_make_targets.fish | 33 ------------------- 2 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 share/functions/__fish_print_make_targets.fish diff --git a/share/completions/make.fish b/share/completions/make.fish index 083e867f3..11d425924 100644 --- a/share/completions/make.fish +++ b/share/completions/make.fish @@ -1,4 +1,37 @@ # Completions for make +function __fish_print_make_targets --argument-names directory file + # Since we filter based on localized text, we need to ensure the + # text will be using the correct locale. + set -lx LC_ALL C + + if test -z "$directory" + set directory '.' + end + + if test -z "$file" + for standard_file in $directory/{GNUmakefile,Makefile,makefile} + if test -f $standard_file + set file $standard_file + break + end + end + end + + set -l bsd_make + if make --version 2>/dev/null | string match -q 'GNU*' + set bsd_make 0 + else + set bsd_make 1 + end + + if test "$bsd_make" = 0 + # https://stackoverflow.com/a/26339924 + make -C "$directory" -f "$file" -pRrq : 2>/dev/null | awk -v RS= -F: '/^# Files/,/^# Finished Make data base/ {if ($1 !~ "^[#.]") {print $1}}' 2>/dev/null + else + make -C "$directory" -f "$file" -d g1 -rn >/dev/null 2>| awk -F, '/^#\*\*\* Input graph:/,/^$/ {if ($1 !~ "^#... ") {gsub(/# /,"",$1); print $1}}' 2>/dev/null + end +end + function __fish_complete_make_targets set directory (string replace -r '^make .*(-C ?|--directory(=| +))([^ ]*) .*$' '$3' -- $argv) if not test $status -eq 0 -a -d $directory diff --git a/share/functions/__fish_print_make_targets.fish b/share/functions/__fish_print_make_targets.fish deleted file mode 100644 index fb8ce9c03..000000000 --- a/share/functions/__fish_print_make_targets.fish +++ /dev/null @@ -1,33 +0,0 @@ -function __fish_print_make_targets --argument-names directory file - # Since we filter based on localized text, we need to ensure the - # text will be using the correct locale. - set -lx LC_ALL C - - if test -z "$directory" - set directory '.' - end - - if test -z "$file" - for standard_file in $directory/{GNUmakefile,Makefile,makefile} - if test -f $standard_file - set file $standard_file - break - end - end - end - - set -l bsd_make - if make --version 2>/dev/null | string match -q 'GNU*' - set bsd_make 0 - else - set bsd_make 1 - end - - if test "$bsd_make" = 0 - # https://stackoverflow.com/a/26339924 - make -C "$directory" -f "$file" -pRrq : 2>/dev/null | awk -v RS= -F: '/^# Files/,/^# Finished Make data base/ {if ($1 !~ "^[#.]") {print $1}}' 2>/dev/null - else - make -C "$directory" -f "$file" -d g1 -rn >/dev/null 2>| awk -F, '/^#\*\*\* Input graph:/,/^$/ {if ($1 !~ "^#... ") {gsub(/# /,"",$1); print $1}}' 2>/dev/null - end -end -