Skip to content

Commit

Permalink
Allow fish comp to support trailing empty lines (#1284)
Browse files Browse the repository at this point in the history
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 <marc.khouzam@montreal.ca>
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
  • Loading branch information
marckhouzam and krobelus committed May 3, 2021
1 parent 3ed6a39 commit 06e4b59
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fish_completions.go
Expand Up @@ -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]
Expand Down

0 comments on commit 06e4b59

Please sign in to comment.