Autocomplete for NPM is outputting "garbage" when nvm plugin is installed
nomaed opened this issue · 13 comments
Originally opened as a fish-shell issue: fish-shell/fish-shell#3152
After installing the nvm
plugin, I get garbage printed out when trying to get auto-completions for npm.
Removing nvm
plugin makes everything work fine.
Operating system: OS X El Capitan 10.11.5 (15F34)
Fish version: 2.3.0
Fish installed: using the official DMG.
Fish location: /usr/local/bin/fish
Terminal: iTerm2
Output:
$ npm <Tab>
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\>/dev/null\)\)\ \|\|\ return\ \$\?
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_LINE=\"\$COMP_LINE\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_POINT=\"\$COMP_POINT\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ npm\ completion\ --\ \"\$\{words\[@\]\}\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\>/dev/null\)\)\ \|\|\ return\ \$\?
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_LINE=\"\$line\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_POINT=\"\$point\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ npm\ completion\ --\ \"\$\{words\[@\]\}\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\>/dev/null\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_LINE=\$BUFFER\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_POINT=0\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ npm\ completion\ --\ \"\$\{words\[@\]\}\"\ \\
\ \ \ \ \ \ _get_comp_words_by_ref\ -n\ =\ -n\ @\ -w\ words\ -i\ cword
\ \ \ \ \ \ cword=\"\$COMP_CWORD\"
\ \ \ \ \ \ words=\(\"\$\{COMP_WORDS\[@\]\}\"\)
\ \ \ \ compadd\ --\ \$\(COMP_CWORD=\$\(\(CURRENT-1\)\)\ \\
\ \ \ \ else
\ \ \ \ fi
\ \ \ \ if\ type\ _get_comp_words_by_ref\ \&\>/dev/null\;\ then
\ \ \ \ IFS=\"\$si\"
\ \ \ \ IFS=\$\'\\n\'\ COMPREPLY=\(\$\(COMP_CWORD=\"\$cword\"\ \\
\ \ \ \ IFS=\$\'\\n\'\ reply=\(\$\(COMP_CWORD=\"\$cword\"\ \\
\ \ \ \ IFS=\$si
\ \ \ \ let\ cword-=1
\ \ \ \ local\ cword\ line\ point\ words\ si
\ \ \ \ local\ si=\"\$IFS\"
\ \ \ \ local\ si=\$IFS
\ \ \ \ local\ words\ cword
\ \ \ \ read\ -Ac\ words
\ \ \ \ read\ -cn\ cword
\ \ \ \ read\ -l\ line
\ \ \ \ read\ -ln\ point
\ \ \ \ si=\"\$IFS\"
\ \ _npm_completion\ \(\)\ \{
\ \ _npm_completion\(\)\ \{
\ \ compctl\ -K\ _npm_completion\ npm
\ \ compdef\ _npm_completion\ npm
\ \ complete\ -o\ default\ -F\ _npm_completion\ npm
\ \ \}
\#
\#\ Installation:\ npm\ completion\ \>\>\ \~/.bashrc\ \ \(or\ \~/.zshrc\)
\#\ npm\ command\ completion\ script
\#\ Or,\ maybe:\ npm\ completion\ \>\ /usr/local/etc/bash_completion.d/npm
\#\#\#-begin-npm-completion-\#\#\#
\#\#\#-end-npm-completion-\#\#\#
add-user (Add a registry user account)
adduser (Add a registry user account)
bin (Display npm bin folder)
bugs (Bugs for a package in a web browser maybe)
c (Manage the npm configuration files)
cache (Manipulates package's cache)
config (Manage the npm configuration files)
ddp (Reduce duplication)
dedupe (Reduce duplication)
deprecate (Deprecate a version of a package)
docs (Docs for a package in a web browser maybe)
edit (Edit an installed package)
elif\ type\ compctl\ \&\>/dev/null\;\ then
elif\ type\ compdef\ \&\>/dev/null\;\ then
explore (Browse an installed package)
faq (Frequently Asked Questions)
fi
find (Search for packages)
find-dupes (Reduce duplication)
get (Echo the config value to stdout)
help-search (Search npm help documentation)
home (Docs for a package in a web browser maybe)
i (install a package)
if\ type\ complete\ \&\>/dev/null\;\ then
info (View registry info)
install (install a package)
isntall (install a package)
issues (Bugs for a package in a web browser maybe)
la (List installed packages)
link (Symlink a package folder)
rows 1 to 75 of 118
Thanks for reporting the issue I will take a look during the weekend.
Thanks.
Just wanted to let you know that if I install omf
nvm, it works well.
Also, I tried installing only bass
, following the advice from here nvm-sh/nvm#303 (comment)
function nvm
bass source ~/.nvm/nvm.sh ';' nvm $argv
end
was enough to make everything work without the whole nvm package.
You don't need this plugin at all, as you said just putting that on your config.fish is enough. What I don't like is if you do that slows your shell initiation by a couple of seconds, because it sources nvm everytime. That's why I created this plugin, to only source nvm when you use npm, or node or nvm
If I add this as a new file, nvm.fish
in the functions directory, shouldn't it do the same - source nvm only when the command is actually called?
@BRJ I want to use nvm. I need to test stuff on different node versions and it makes the job much easier than I would be otherwise.
Edit: I looked into fnm, and I'll give it a try. I need stuff that can work outside of fish as well.
So, I installed fnm (fisher install fnm
), got the latest node.
Now I'm getting this as an output for npm<Tab>
on Ubuntu 16.04:
╰▶ npm
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\>/dev/null\)\)\ \|\|\ return\ \$\?
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_LINE=\"\$COMP_LINE\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_POINT=\"\$COMP_POINT\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ npm\ completion\ --\ \"\$\{words\[@\]\}\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\>/dev/null\)\)\ \|\|\ return\ \$\?
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_LINE=\"\$line\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_POINT=\"\$point\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ npm\ completion\ --\ \"\$\{words\[@\]\}\"\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 2\>/dev/null\)
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_LINE=\$BUFFER\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ COMP_POINT=0\ \\
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ npm\ completion\ --\ \"\$\{words\[@\]\}\"\ \\
\ \ \ \ \ \ _get_comp_words_by_ref\ -n\ =\ -n\ @\ -w\ words\ -i\ cword
\ \ \ \ \ \ cword=\"\$COMP_CWORD\"
\ \ \ \ \ \ words=\(\"\$\{COMP_WORDS\[@\]\}\"\)
\ \ \ \ compadd\ --\ \$\(COMP_CWORD=\$\(\(CURRENT-1\)\)\ \\
\ \ \ \ else
\ \ \ \ fi
\ \ \ \ if\ type\ _get_comp_words_by_ref\ \&\>/dev/null\;\ then
\ \ \ \ IFS=\"\$si\"
\ \ \ \ IFS=\$\'\\n\'\ COMPREPLY=\(\$\(COMP_CWORD=\"\$cword\"\ \\
\ \ \ \ IFS=\$\'\\n\'\ reply=\(\$\(COMP_CWORD=\"\$cword\"\ \\
\ \ \ \ IFS=\$si
\ \ \ \ let\ cword-=1
\ \ \ \ local\ cword\ line\ point\ words\ si
\ \ \ \ local\ si=\"\$IFS\"
\ \ \ \ local\ si=\$IFS
\ \ \ \ local\ words\ cword
\ \ \ \ read\ -Ac\ words
\ \ \ \ read\ -cn\ cword
\ \ \ \ read\ -l\ line
\ \ \ \ read\ -ln\ point
\ \ \ \ si=\"\$IFS\"
\ \ _npm_completion\ \(\)\ \{
\ \ _npm_completion\(\)\ \{
\ \ compctl\ -K\ _npm_completion\ npm
\ \ compdef\ _npm_completion\ npm
\ \ complete\ -o\ default\ -F\ _npm_completion\ npm
\ \ \}
\#
\#\ Installation:\ npm\ completion\ \>\>\ \~/.bashrc\ \ \(or\ \~/.zshrc\)
\#\ npm\ command\ completion\ script
\#\ Or,\ maybe:\ npm\ completion\ \>\ /usr/local/etc/bash_completion.d/npm
\#\#\#-begin-npm-completion-\#\#\#
\#\#\#-end-npm-completion-\#\#\#
add-user (Add a registry user account)
adduser (Add a registry user account)
bin (Display npm bin folder)
bugs (Bugs for a package in a web browser maybe)
c (Manage the npm configuration files)
cache (Manipulates package's cache)
config (Manage the npm configuration files)
ddp (Reduce duplication)
dedupe (Reduce duplication)
deprecate (Deprecate a version of a package)
docs (Docs for a package in a web browser maybe)
edit (Edit an installed package)
elif\ type\ compctl\ \&\>/dev/null\;\ then
elif\ type\ compdef\ \&\>/dev/null\;\ then
explore (Browse an installed package)
faq (Frequently Asked Questions)
fi
find (Search for packages)
find-dupes (Reduce duplication)
get (Echo the config value to stdout)
help-search (Search npm help documentation)
home (Docs for a package in a web browser maybe)
i (install a package)
if\ type\ complete\ \&\>/dev/null\;\ then
info (View registry info)
install (install a package)
isntall (install a package)
issues (Bugs for a package in a web browser maybe)
la (List installed packages)
link (Symlink a package folder)
list (List installed packages)
ll (List installed packages)
╰▶ fish -v
fish, version 2.3.0
╰▶ fnm -v
fnm v1.8.0
╰▶ fisher -v
fisherman version 2.10.0 ~/.config/fish/functions/fisher.fish
╰▶ npm -v
3.10.1
╰▶ nvm -v
No command 'nvm' found
Btw fnm has nothing to do with nvm.
Now, I was able to repro the problem with npm completions.
npm completions work okay with verman (which is what I use now).
Would you mind trying out verman also to see if npm completions work fine for you? That would help me determine this is a problem with how fnm creates the npm shim or npm (completions) itself.
I think the problem may be simply that fnm's npm shim is not inheriting npm completions. This should be doable adding --wraps=npm
to the function definition, maybe.
I think it has to do with fish-shell npm completions https://github.com/fish-shell/fish-shell/blob/master/share/completions/npm.fish
As soon I renamed the file /usr/share/fish/completions/npm.fish
there's no more auto complete with "garbage". So now I need to discover if the problem is with Bass or with this plugin
@nomaed It seems after all that the problem was not with the plugin, but with the official completions from fish shell, you can read more about it here fish-shell/fish-shell#3159
And the commit that fixes it fish-shell/fish-shell@10661bb :
The next release of fish shell will have the completions fixed but until then you can fix them manually by doing this:
wget https://raw.githubusercontent.com/fish-shell/fish-shell/master/share/completions/npm.fish
and then do sudo mv npm.fish /usr/share/fish/completions/
That is great, thank you for following it up!