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

~/.opam/opam-init/env_hook.sh is not executed when init.sh is called from .bash_profile #3990

Open
jhjourdan opened this issue Sep 20, 2019 · 3 comments

Comments

@jhjourdan
Copy link

At least on my machine (Fedora 29), ~/.opam/opam-init/env_hook.sh is not executed from init.sh when called from .bash_profile. The resaon is that it seems like .bash_profile is executed once when I open my user session, and stdout is not bound to a terminal at that time.

Hence, the test

if [ -t 0 ]; then
  test -r /home/jjourdan/.opam/opam-init/complete.sh && . /home/jjourdan/.opam/opam-init/complete.sh > /dev/null 2> /dev/null || true

  test -r /home/jjourdan/.opam/opam-init/env_hook.sh && . /home/jjourdan/.opam/opam-init/env_hook.sh > /dev/null 2> /dev/null || true
fi

is ignored.

@rjbou
Copy link
Collaborator

rjbou commented Sep 26, 2019

Shell startup loading can be nonsensical sometimes, and quite difficult to raise a general usability consensus (cf. #1447, #533, etc.).

You can change the default configuration file to update, and set it up as .bashrc or another setup file, to be sure to have at each terminal opening, with opam init --reinit.

@jhjourdan
Copy link
Author

Yes, I already added the correct call in .bashrc in my configuration. I just think it is sad that people continue typing eval $(opam env) while shell hooks exist and can be made working.

More precisely : in many cases, if using a graphical interface (i.e., there is no actual "login shell"), .bash_profile will be run in a non-interactive context at login time, and shell hooks will not be setup. So, if we want them to be setup reliably, perhaps the right thing to do is to call variables.sh from .bash_profile and complete.sh and env_hook.sh from .bashrc. Don't you think?

@rjbou
Copy link
Collaborator

rjbou commented May 11, 2020

If variables.sh is in .bash_profile, it will only be run once at session opening, and new non login shells won't be updated if the shell hook is not enabled.

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

2 participants