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

Feature request: command to show env status #3725

Closed
rymdhund opened this issue Jan 21, 2019 · 5 comments · Fixed by #4074
Closed

Feature request: command to show env status #3725

rymdhund opened this issue Jan 21, 2019 · 5 comments · Fixed by #4074

Comments

@rymdhund
Copy link

I'm always having trouble with is keeping track of when I need to run eval $(opam env). For example when cd-ing between a local switches. If there was a quick way to query opam about when I needed to update my env it would be easy to write a shell plugin that automatically reconfigures the env when needed.

For example a command like this would do the trick:

opam env --status

That returns Env is up to date or Run 'eval $(opam env)'

This might also be useful for dune to give a hint that you forgot to configure the env when your build fails.

Does this feature make sense? In that case I could try to put together some kind of pull request.

@rymdhund rymdhund changed the title Feature request: Feature request: command to show env status Jan 21, 2019
@hcarty
Copy link
Member

hcarty commented Jan 22, 2019

opam 2 supports automatically changing switches as you navigate in your shell. I'm not sure where that code lives in the source tree, but it should provide a good starting point if the built-in support doesn't work for your setup.

@rjbou
Copy link
Collaborator

rjbou commented Jan 22, 2019

Indeed, at opam init (or replaying it) you can enable a shell hook that evaluates opam env at each prompt, making it constantly up to date.
You can find in this initial PR #3304 discussion, example of use, and involved files.
Does that cover your case?

@rymdhund
Copy link
Author

@rjbou Ah, yes I'm not using the hooks that opam init wants to create since I like to manage my shell config myself. But you're right that I could probably just update the env on every command.

However what I really want to do is show a flag in my prompt when my opam env is out of sync. And I don't think this is possible using any existing commands?

@rjbou
Copy link
Collaborator

rjbou commented Jan 22, 2019

Usually, one easy way that covers most of the cases (not some tricky ones) is that your env is out of sync when the switch prefix doesn't match opam's one. So, a light check is to add on your prompt command something like

[ "x`opam var prefix`" = "x$OPAM_SWITCH_PREFIX" ] || echo "Update!"

Shell hook files can be found in <opam>/opam-init/env_hook.{sh,csh,zsh,fish}, you can take a look and add at you convenience in you config

@AltGr
Copy link
Member

AltGr commented Jan 23, 2019

opam switch does print such a warning, but probably not in an easily usable format

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