edc / bass

Make Bash utilities usable in Fish shell
MIT License
2.2k stars 70 forks source link

while sourcing nvm command works, npm and node command are not working properly #28

Closed shangsunset closed 8 years ago

shangsunset commented 8 years ago

Hi, So ive put the nvm function in the config.fish and installed node with nvm. however, i always get fish: Unknown command 'node' on shell startup, so is npm. they will work after i execute a nvm command though, such as nvm ls.

if nvm is already sourced, how come node wont work?

ps: tested in bash. node and npm work normally.

my config.fish:

# Fisherman config
set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman
source $fisher_home/config.fish

# Initial config file contents, which adds /usr/local/bin to the PATH environment variable.
set -g -x PATH /usr/local/bin $PATH

# Homebrew
set -g -x PATH /usr/local/sbin $PATH

# pyenv
status --is-interactive; and . (pyenv init -|psub)

function nvm
    bass source ~/.nvm/nvm.sh ';' nvm $argv
end

# Will eliminate the Fish welcome message that appears by default
set -g -x fish_greeting ''
ghost commented 8 years ago

@shangsunset For starters, I think the correct function is:

function nvm
     bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
edc commented 8 years ago

@shangsunset let me know if what @bucaran suggested works for you.

shangsunset commented 8 years ago

unfortunately, it didnt work.

ghost commented 8 years ago

@shangsunset

Why the following?

set -g -x PATH /usr/local/bin $PATH

isn't /usr/local/bin/ supposed to be in PATH by default?

And one more thing, neither node or npm are in your $PATH when the sessions starts. So, try

printf "%s\n" $PATH
shangsunset commented 8 years ago

Hey @bucaran, I deleted set -g -x PATH /usr/local/bin $PATH and this is the output from running printf "%s\n" $PATH:

/Users/shangsunset/.pyenv/shims
/usr/local/sbin
/Users/shangsunset/.nvm/versions/node/v5.10.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
ghost commented 8 years ago

/Users/shangsunset/.nvm/versions/node/v5.10.1/bin shows first than /usr/local/bin, which makes sense, but what's inside the nvm path?

ls -la /Users/shangsunset/.nvm/versions/node/v5.10.1/bin
shangsunset commented 8 years ago
total 46224
drwxr-xr-x   4 shangsunset  staff       136 Apr  5 17:47 .
drwxr-xr-x  10 shangsunset  staff       340 Apr 15 09:34 ..
-rwxr-xr-x   1 shangsunset  staff  23661896 Apr  5 17:47 node
lrwxr-xr-x   1 shangsunset  staff        38 Apr  5 17:47 npm -> ../lib/node_modules/npm/bin/npm-cli.js
ghost commented 8 years ago

And you are saying that when you run, npm or node, you get a "command not found" error?

shangsunset commented 8 years ago

yes

ghost commented 8 years ago

And what happens if you do

/Users/shangsunset/.nvm/versions/node/v5.10.1/bin/node -v
ghost commented 8 years ago

Also, do you have a .bash_profile file in your $HOME directory? and if you do, what is its contents?

shangsunset commented 8 years ago
shangsunset@Yeshens-MBP ~> /Users/shangsunset/.nvm/versions/node/v5.10.1/bin/node -v
v5.10.1
shangsunset@Yeshens-MBP ~> cat .bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
shangsunset@Yeshens-MBP ~>

does .bash_profile still matter if we are using fish?

ghost commented 8 years ago

Right, it does not matter in fish, but nvm is a bash script and I wanted to see if you were defining any aliases.

If /Users/shangsunset/.nvm/versions/node/v5.10.1/bin/node works, how come node, does not?

Try this:

set -gx PATH /Users/shangsunset/.nvm/versions/node/v5.10.1/bin

and run node again. If that does not work, comment out your .bash_profile and try again. I don't know how nvm works internally, so that's just a desperate measure.

shangsunset commented 8 years ago

mmm that works

ghost commented 8 years ago

Okay, can you check what's inside:

/Users/shangsunset/.pyenv/shims
/usr/local/sbin
shangsunset commented 8 years ago
shangsunset@Yeshens-MBP ~> ls -la /Users/shangsunset/.pyenv/shims
total 0
drwxr-xr-x  2 shangsunset  staff   68 Apr 16 00:31 .
drwxr-xr-x  4 shangsunset  staff  136 Apr 11 10:50 ..
shangsunset@Yeshens-MBP ~> ls -la /usr/local/sbin
total 16
drwxr-xr-x   4 shangsunset  admin  136 Apr 12 09:04 .
drwxrwxr-x  20 shangsunset  admin  680 Apr 12 10:07 ..
lrwxr-xr-x   1 shangsunset  admin   35 Apr 12 09:04 php-fpm -> ../Cellar/php56/5.6.20/sbin/php-fpm
lrwxr-xr-x   1 shangsunset  admin   37 Apr 12 09:04 php56-fpm -> ../Cellar/php56/5.6.20/sbin/php56-fpm
shangsunset@Yeshens-MBP ~>
ghost commented 8 years ago

Well, that looks alright, I guess.

Comment out all of your config.fish, and just leave this

set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman
source $fisher_home/config.fish

function nvm
   bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

Then reload the shell and try using nvm as you are used to again.

shangsunset commented 8 years ago

still getting fish: Unknown command 'node' :( so weird. i can use nvm to install node but node is unknown...

ghost commented 8 years ago

And if you modify your PATH like this?

/Users/shangsunset/.nvm/versions/node/v5.10.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
shangsunset commented 8 years ago

yea node works with /Users/shangsunset/.nvm/versions/node/v5.10.1/bin in PATH

ghost commented 8 years ago

So, the problem is solved. What is the issue again?

shangsunset commented 8 years ago

so i need to put set -gx PATH /Users/shangsunset/.nvm/versions/node/v5.10.1/bin $PATH in my config.fish?

ghost commented 8 years ago

@shangsunset

Nope, that's exactly nvm's job. You need to do is run nvm or nvm use foo when you restart your shell / cd into a path with a .nvmrc, etc., everytime.

Because nvm mods in your PATH will not be persisted across sessions AFIK.

I think you were just using nvm incorrectly, so not your fault, I was confused about this too.

shangsunset commented 8 years ago

I need to run nvm every time when i use node or npm from now on? That doesnt sound very ideal... I wonder why I didnt have to run nvm every time when i was using zsh or omf/plugin-nvm. hmmmm...

ghost commented 8 years ago

@shangsunset

I wonder why I didnt have to run nvm every time when i was using zsh or omf/plugin-nvm. hmmmm...

Well, that's because they either source nvm or call the nvm function for you on shell startup.

Related: https://github.com/creationix/nvm/issues/303#issuecomment-210738874

ghost commented 8 years ago

@shangsunset

Just rm ~/.config/functions/config.fish, and create a new config.fish with this:

set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman
source $fisher_home/config.fish

### add your other configuration here

function nvm
     bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

nvm  ### call nvm HERE so you don't have to call it every time
shangsunset commented 8 years ago

@bucaran

Really appreciate your help and patience. However, even though i deleted my existing config.fish and created a new one with what you provided, node and npm are still not available upon shell start. unless i run nvm use node.

ghost commented 8 years ago

@shangsunset I think you could make your life a ton easier if you switched to tj/n, at least just temporarily until you figure out how nvm works.

https://github.com/tj/n

If you really want to use nvm, though, I advise you to read their documentation thoroughly and learn how to use it instead of depending on plugins first.

Also, please read the "official" fish tutorial. Please take no offence, as I could be wrong, but given your responses, it looks as if you still don't really understand the difference between calling a function, running code on shell startup, etc.

shangsunset commented 8 years ago

ok thanks.

ghost commented 8 years ago

@shangsunset https://github.com/fisherman/nvm

ljharb commented 8 years ago

Please do not steal other people's project names.

ghost commented 8 years ago

@ljharb Dude, you are completely misinterpreting my plugin. The purpose of fisherman/nvm is to serve as a bridge between creationix/nvm and the missing nvm solution in fish.

ljharb commented 8 years ago

I did - I asked you politely to change it. You said "No". call it nvm-fish if you like - but not "nvm". That's confusing for users, and makes googling harder, even if it wasn't rude and potentially an implicit trademark violation.

ghost commented 8 years ago

People that use fisherman know that stuff inside the org, are all plugins for fish, kind of like ohmyfish and similar projects. I wouldn't say it's confusing.

ljharb commented 8 years ago

You were politely asked by a project whose name you copied to change it. Whether you agree that it's confusing is irrelevant - it's not cool, under any circumstances.

ghost commented 8 years ago

First, you were not polite, you were not rude either, but you were definitely very hostile. You even called me an "asshole". Why should I accept that? People on the internet are very confrontational when facing a white message box. You wouldn't call me an asshole to my face.

Second, I worked hard on this thing, not that it matters, but I put it there because a lot of people have asked for an nvm in fish for like years and there just wasn't one. Sure, there are wrappers, but it's just not the same. I am calling the project nvm for a simple reason, people migrating from bash to fish that have used creationix/nvm before, are likely to search for "nvm in fish" when they realize creationix/nvm does not work in fish.

ljharb commented 8 years ago

so call it "nvm in fish". I insulted you after you posted a very rude one-word answer "No", and after you called me "bro" (which is also rude; you don't know me) and told me to "chill".

I'm glad you worked hard on it, and I hope your project is successful - but it should be successful under its own name, not by stealing the name of something else. If you don't change your name, and your project attains any notoriety, it will forever live under the shadow of that - I won't be the only one you hear it from. Why not just change it?

ghost commented 8 years ago

Well, that's a touching way to put it. There you go: https://github.com/fisherman/nbm ;)

And, I said "dude". From there to asshole it's quite a big jump.

EDIT: Went with https://github.com/fisherman/fish-nvm

EDIT 2: Went with https://github.com/fisherman/fin lol

ljharb commented 8 years ago

Thanks, much obliged.

ghost commented 8 years ago

@ljharb See edit. If that's okay with you I'd like to add it to the list of alternatives in your README.

ljharb commented 8 years ago

@bucaran thank you, that sounds great. Please feel free to send a PR.

FabioAntunes commented 8 years ago

@bucaran fish-nvm was way better than fin, it's very funny naming stuff after fishes and stuff related to them, but that makes googling hard as hell.

If I want a nvm for fish I will search for that on google, not fin. If I want to run bash script on my fish shell I will search for fish bash wrapper or fish bash runner, not bass.

@shangsunset You can solve your problem sourcing nvm every time you open a new shell, this will add a minor delay, but at least it works, just put this line on your config file at ~/.config/fish/config.fish

bass source ~/.nvm/nvm.sh >/dev/null ^&1

ghost commented 8 years ago

@FabioAntunes Which is why I named it nvm in the first place, but then ljharb was right, I can't just name my project after creationix/nvm like that, so I changed it to fin.

Now, bear in mind that fin is not a drop-in replacement for nvm nor it requires nvm as a dependency. It's a standalone node version manager written in fish.

If I want a nvm for fish I will search for that on google, not fin. If I want to run bash script on my fish shell I will search for fish bash wrapper or fish bash runner, not bass.

I couldn't agree more, and just like fisherman, SEO will be hard to do. Now, on the other hand, those who find it will appreciate it like the hidden gem it is.