buildbuddy-io / bazel_env.bzl

A virtual environment for Bazel-managed tools and toolchains.
MIT License
24 stars 1 forks source link

zsh: rehash after adding commands #15

Open kolloch opened 3 months ago

kolloch commented 3 months ago

If you add commands to the current environment, zsh might not pick them up if it has already cached the resolved path of another location.

To reproduce

  1. Use zsh
  2. Have a locally installed JDK
  3. enable some bazel_env via direnv
  4. which jstack --> should output the globally installed one
  5. Add jstack to the bazel_env
  6. which jstack --> still points to the global one, nothing changed
  7. rehash
  8. which jstack --> points to the bazel_env one
fmeum commented 3 months ago

We could just run rehash in bazel run //:bazel_env if we detect that we are running in zsh. I don't have much experience with zsh, would you be interested in sending a PR I could review?

kolloch commented 3 months ago

I think that the bazel_env command is executed in a subshell, and rehash needs to be executed in the affected shell.

I do think that it probably has to be added to direnv in some way. Or maybe there already is a way via direnv.

Maybe similarly to what has been done for auto-complete here: https://github.com/direnv/direnv/issues/443#issuecomment-1992019782

I'll try to find a nice solution there.