Skip to content

Commit

Permalink
Merge pull request #610 from rsteube/zsh-fix-suffix
Browse files Browse the repository at this point in the history
zsh: fix conditional nospace
  • Loading branch information
rsteube authored Nov 24, 2022
2 parents 292120b + c42e4b9 commit 6d9a247
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
11 changes: 2 additions & 9 deletions example/cmd/_test/zsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/shell/zsh/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 2 additions & 9 deletions internal/shell/zsh/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d9a247

Please sign in to comment.