plugin-foreign-env icon indicating copy to clipboard operation
plugin-foreign-env copied to clipboard

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

Open ghost opened this issue 7 years ago • 2 comments

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 avatar Dec 14 '18 21:12 ghost

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 avatar Dec 14 '18 21:12 ghost

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

ghost avatar Dec 14 '18 22:12 ghost