From 38e7fe9d4f723418e04878b530e5dc0ac5efeab1 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Thu, 14 Apr 2022 12:01:21 +0300 Subject: [PATCH] ZSH completion tried to parse directive from the wrong line (it is available on the second to last line, not last line). Modify the behavior in completion to remove the last line from output and the directive. --- zsh_completions.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/zsh_completions.go b/zsh_completions.go index c6048a9e..3a421a7d 100644 --- a/zsh_completions.go +++ b/zsh_completions.go @@ -135,22 +135,26 @@ _%[1]s() out=$(eval ${requestComp} 2>/dev/null) __%[1]s_debug "completion output: ${out}" - # Extract the directive integer following a : from the last line + # Extract the directive integer following a : + directive=0 + __kubecm_debug "Extracting directive from the output" local lastLine while IFS='\n' read -r line; do lastLine=${line} - done < <(printf "%%s\n" "${out[@]}") - __%[1]s_debug "last line: ${lastLine}" + if [ "${#lastLine}" -eq 2 ] && [ "${lastLine[1]}" = : ]; then + directive=${lastLine[2,-1]} + fi + done < <(printf "%s\n" "${out[@]}") + __kubecm_debug "last line: ${lastLine}" - if [ "${lastLine[1]}" = : ]; then - directive=${lastLine[2,-1]} - # Remove the directive including the : and the newline + # Remove the last line and directive including the : and the newline + if [ $directive -gt 0 ]; then local suffix - (( suffix=${#lastLine}+2)) + (( suffix=${#lastLine}+5)) out=${out[1,-$suffix]} else # There is no directive specified. Leave $out as is. - __%[1]s_debug "No directive found. Setting do default" + __kubecm_debug "No directive found. Setting do default" directive=0 fi