Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete for NPM is outputting "garbage" when nvm plugin is installed #4

Closed
nomaed opened this issue Jun 18, 2016 · 13 comments · Fixed by #5 or #6
Closed

Autocomplete for NPM is outputting "garbage" when nvm plugin is installed #4

nomaed opened this issue Jun 18, 2016 · 13 comments · Fixed by #5 or #6

Comments

@nomaed
Copy link

nomaed commented Jun 18, 2016

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
@FabioAntunes
Copy link
Owner

Thanks for reporting the issue I will take a look during the weekend.

@nomaed
Copy link
Author

nomaed commented Jun 18, 2016

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.

@FabioAntunes
Copy link
Owner

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

@nomaed
Copy link
Author

nomaed commented Jun 18, 2016

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?

@ghost
Copy link

ghost commented Jun 19, 2016

@nomaed Do you really have to use nvm?

Some people have to use nvm, so this exists, but as you can see setting it up requires knowledge and some work which is why fnm also exists.

@nomaed
Copy link
Author

nomaed commented Jun 19, 2016

@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.

@nomaed
Copy link
Author

nomaed commented Jun 19, 2016

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

@ghost
Copy link

ghost commented Jun 19, 2016

Btw fnm has nothing to do with nvm.

Now, I was able to repro the problem with npm completions.

screenshot 2016-06-20 01 10 25

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.

https://github.com/fisherman/verman

@ghost
Copy link

ghost commented Jun 19, 2016

With verman

screenshot 2016-06-20 01 15 25

@ghost
Copy link

ghost commented Jun 19, 2016

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.

@FabioAntunes
Copy link
Owner

FabioAntunes commented Jun 19, 2016

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

@FabioAntunes
Copy link
Owner

@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/

@nomaed
Copy link
Author

nomaed commented Jun 22, 2016

That is great, thank you for following it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants