Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Whiteley <greg.whiteley@atomos.com>2015-05-06 07:45:33 +0300
committerRebecca Turner <me@re-becca.org>2015-08-08 02:06:46 +0300
commit04ec77b5c407cbfd8a1241528fd5e2d97ce3efb7 (patch)
treeb09c3f2b5157be7d524a2f5eb485a15d0989970b /lib
parent9a3de6e8bc3d2b7cb2e8c6a5560bdb4f7b024145 (diff)
completion: don't break global COMP_WORDBREAKS
As described in #4530, #5820 modification of global variable COMP_WORDBREAKS causes global breakage of completion: ``` dd if=/dev/ze<tab> -> dd /dev/zero ``` Fixes: #4530 PR-URL: https://github.com/npm/npm/pull/8892
Diffstat (limited to 'lib')
-rwxr-xr-xlib/utils/completion.sh16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/utils/completion.sh b/lib/utils/completion.sh
index 3c7a3590d..25bef2c17 100755
--- a/lib/utils/completion.sh
+++ b/lib/utils/completion.sh
@@ -7,17 +7,21 @@
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
#
-COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
-COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
-export COMP_WORDBREAKS
-
if type complete &>/dev/null; then
_npm_completion () {
+ local words cword
+ if type _get_comp_words_by_ref &>/dev/null; then
+ _get_comp_words_by_ref -n = -n @ -w words -i cword
+ else
+ cword="$COMP_CWORD"
+ words=("${COMP_WORDS[@]}")
+ fi
+
local si="$IFS"
- IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
+ IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
- npm completion -- "${COMP_WORDS[@]}" \
+ npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}