From 2fefd9eea4db910eae2b3b86f4834d0892b659dc Mon Sep 17 00:00:00 2001 From: knight42 Date: Wed, 25 Mar 2020 22:54:33 +0800 Subject: [PATCH] fix(kubectl): remove trailing space when completing file path --- .../kubectl/pkg/cmd/completion/completion.go | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/completion/completion.go b/staging/src/k8s.io/kubectl/pkg/cmd/completion/completion.go index d286761b27d..367e7e38bf5 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/completion/completion.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/completion/completion.go @@ -223,49 +223,9 @@ __kubectl_get_comp_words_by_ref() { } __kubectl_filedir() { - local RET OLD_IFS w qw - - __kubectl_debug "_filedir $@ cur=$cur" - if [[ "$1" = \~* ]]; then - # somehow does not work. Maybe, zsh does not call this at all - eval echo "$1" - return 0 - fi - - OLD_IFS="$IFS" - IFS=$'\n' - if [ "$1" = "-d" ]; then - shift - RET=( $(compgen -d) ) - else - RET=( $(compgen -f) ) - fi - IFS="$OLD_IFS" - - IFS="," __kubectl_debug "RET=${RET[@]} len=${#RET[@]}" - - for w in ${RET[@]}; do - if [[ ! "${w}" = "${cur}"* ]]; then - continue - fi - if eval "[[ \"\${w}\" = *.$1 || -d \"\${w}\" ]]"; then - qw="$(__kubectl_quote "${w}")" - if [ -d "${w}" ]; then - COMPREPLY+=("${qw}/") - else - COMPREPLY+=("${qw}") - fi - fi - done -} - -__kubectl_quote() { - if [[ $1 == \'* || $1 == \"* ]]; then - # Leave out first character - printf %q "${1:1}" - else - printf %q "$1" - fi + # Don't need to do anything here. + # Otherwise we will get trailing space without "compopt -o nospace" + true } autoload -U +X bashcompinit && bashcompinit