From c42e4b9022ec2f4d0edf62166975d3023e7b0b8a Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 24 Nov 2022 22:54:42 +0100 Subject: [PATCH] zsh: fix conditional nospace --- example/cmd/_test/zsh.sh | 11 ++--------- internal/shell/zsh/action.go | 4 ++-- internal/shell/zsh/snippet.go | 11 ++--------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/example/cmd/_test/zsh.sh b/example/cmd/_test/zsh.sh index 48be4b459..03ca7905f 100644 --- a/example/cmd/_test/zsh.sh +++ b/example/cmd/_test/zsh.sh @@ -15,22 +15,15 @@ function _example_completion { fi export ZLS_COLOURS="${lines[1]}" - #zstyle ":completion:${curcontext}:*" list-colors "${lines[1]}" # shellcheck disable=SC2034,2206 lines=(${lines[@]:1}) - # shellcheck disable=SC2034,2206 - local vals=(${lines%%$'\t'*}) + local vals=(${lines%$'\t'*}) # shellcheck disable=SC2034,2206 local displays=(${lines##*$'\t'}) - local suffix=' ' - [[ ${vals[1]} == *$'\001' ]] && suffix='' - # shellcheck disable=SC2034,2206 - vals=(${vals%%$'\001'*}) - - compadd -Q -S "${suffix}" -d displays -a -- vals + compadd -Q -S '' -a -d displays -- vals } compquote '' 2>/dev/null && _example_completion compdef _example_completion example diff --git a/internal/shell/zsh/action.go b/internal/shell/zsh/action.go index 5e9e59b9f..2f8dd1ab6 100644 --- a/internal/shell/zsh/action.go +++ b/internal/shell/zsh/action.go @@ -78,8 +78,8 @@ func ActionRawValues(currentWord string, nospace common.SuffixMatcher, values co for index, val := range filtered { val.Value = sanitizer.Replace(val.Value) val.Value = quoteValue(val.Value) - if nospace.Matches(val.Value) { - val.Value = val.Value + "\001" + if !nospace.Matches(val.Value) { + val.Value = val.Value + " " } val.Display = sanitizer.Replace(val.Display) val.Description = sanitizer.Replace(val.Description) diff --git a/internal/shell/zsh/snippet.go b/internal/shell/zsh/snippet.go index ccfe92da1..816a69e28 100644 --- a/internal/shell/zsh/snippet.go +++ b/internal/shell/zsh/snippet.go @@ -27,22 +27,15 @@ function _%v_completion { fi export ZLS_COLOURS="${lines[1]}" - #zstyle ":completion:${curcontext}:*" list-colors "${lines[1]}" # shellcheck disable=SC2034,2206 lines=(${lines[@]:1}) - # shellcheck disable=SC2034,2206 - local vals=(${lines%%%%$'\t'*}) + local vals=(${lines%%$'\t'*}) # shellcheck disable=SC2034,2206 local displays=(${lines##*$'\t'}) - local suffix=' ' - [[ ${vals[1]} == *$'\001' ]] && suffix='' - # shellcheck disable=SC2034,2206 - vals=(${vals%%%%$'\001'*}) - - compadd -Q -S "${suffix}" -d displays -a -- vals + compadd -Q -S '' -a -d displays -- vals } compquote '' 2>/dev/null && _%v_completion compdef _%v_completion %v