From a574b518ae5b8f0664ed388cf1be6288d8c2e68d Mon Sep 17 00:00:00 2001 From: Nariyasu Heseri Date: Tue, 25 May 2021 23:41:39 +0900 Subject: [PATCH] fix(completion): restore IFS even if `npm completion` returns error PR-URL: https://github.com/npm/cli/pull/3304 Credit: @NariyasuHeseri Close: #3304 Reviewed-by: @wraithgar --- lib/utils/completion.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/utils/completion.sh b/lib/utils/completion.sh index c549b31c96493..a3e5143991edd 100755 --- a/lib/utils/completion.sh +++ b/lib/utils/completion.sh @@ -18,11 +18,15 @@ if type complete &>/dev/null; then fi local si="$IFS" - IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \ + if ! IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \ COMP_LINE="$COMP_LINE" \ COMP_POINT="$COMP_POINT" \ npm completion -- "${words[@]}" \ - 2>/dev/null)) || return $? + 2>/dev/null)); then + local ret=$? + IFS="$si" + return $ret + fi IFS="$si" if type __ltrim_colon_completions &>/dev/null; then __ltrim_colon_completions "${words[cword]}" @@ -49,11 +53,16 @@ elif type compctl &>/dev/null; then read -l line read -ln point si="$IFS" - IFS=$'\n' reply=($(COMP_CWORD="$cword" \ + if ! IFS=$'\n' reply=($(COMP_CWORD="$cword" \ COMP_LINE="$line" \ COMP_POINT="$point" \ npm completion -- "${words[@]}" \ - 2>/dev/null)) || return $? + 2>/dev/null)); then + + local ret=$? + IFS="$si" + return $ret + fi IFS="$si" } compctl -K _npm_completion npm