From 06e4b59b206e16bb8c8f030f1a09bfc39ac5ff03 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Mon, 3 May 2021 12:23:34 -0400 Subject: [PATCH] Allow fish comp to support trailing empty lines (#1284) Some programs may output extra empty lines after the directive. Those lines must be ignored for fish shell completion to work. zsh and bash are not impacted. Signed-off-by: Marc Khouzam Co-authored-by: Johannes Altmanninger Co-authored-by: Johannes Altmanninger --- fish_completions.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fish_completions.go b/fish_completions.go index 3e11234..0b2ff7d 100644 --- a/fish_completions.go +++ b/fish_completions.go @@ -53,6 +53,19 @@ function __%[1]s_perform_completion __%[1]s_debug "Calling $requestComp" set results (eval $requestComp 2> /dev/null) + + # Some programs may output extra empty lines after the directive. + # Let's ignore them or else it will break completion. + # Ref: https://github.com/spf13/cobra/issues/1279 + for line in $results[-1..1] + if test (string trim -- $line) = "" + # Found an empty line, remove it + set results $results[1..-2] + else + # Found non-empty line, we have our proper output + break + end + end set comps $results[1..-2] set directiveLine $results[-1]