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

~/.bashrc is not properly sourced even when --login is passed #16

Open
ghost opened this issue Dec 14, 2018 · 2 comments
Open

~/.bashrc is not properly sourced even when --login is passed #16

ghost opened this issue Dec 14, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 14, 2018

This was a rather difficult one to track down: some distributions have a special clause in their ~/.bashrc that looks something like this (taken from this gist):

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# rest of file with some modifications to $PATH ...

This answer on ServerFault explains in detail why that is, and from the looks of it, for the sake of backwards-compatibility, it isn't going to go away very soon. In my case, it means that the command nvm could not be found, even though my .bashrc was set up correctly.

I propose a small change to the documentation to notify people who are having trouble with this. You can do the following and get it working completely:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
# Adds a special case for when we really do want to modify $PATH
case $- in
    *i*) ;;
      *) [ -z "$FORCE_LOGIN" ] && return;;
esac

Next, wrap the command you would like to run in a function, like so:

function nvm
  begin
    set -lx FORCE_LOAD 1
    fenv nvm $argv
  end
end

Until fish functions are able to accept environment variables, I'm afraid that's the best I can come up with.

@ghost
Copy link
Author

ghost commented Dec 14, 2018

By the way: thanks for the plugin! I really did not want to write one myself, and with some slight modifications (see #15) it works like a charm! 👍

@ghost
Copy link
Author

ghost commented Dec 14, 2018

Hmm seems that I was too quick ... nvm does not modify my $PATH variable and can't find node while it works in plain bash. Maybe it is too good to be true after all ...

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

No branches or pull requests

0 participants