Open amomchilov opened 8 months ago
@amomchilov Could you post your ~/.zshrc
and /etc/zshrc
files? I suspect there's extra logic there that is exiting if the shell is not in interactive mode. On Fedora Linux with zsh 5.9, if I added echo "loaded"
to my ~/.zshrc
, it shows that the configuration file is loaded when running zsh
and zsh -i
.
We cannot always specify -i
because that would assume you are always running in an interactive shell, which might not always be the case (ex: running chruby-exec
in a cronjob).
Also note that chruby-0.3.9 was indeed released 2014-11-23. GitHub releases are separate from the git tags, and I didn't start adding GitHub releases for git tags until much later.
Could you post your ~/.zshrc and /etc/zshrc files? I suspect there's extra logic there that is exiting if the shell is not in interactive mode.
My ~/.zshrc
was pretty extensive, but I minimized it down to the bare minimum (and still reproduced the issue with the steps in the OP):
zsh_user_path=(
"/opt/homebrew/bin"
)
export path=($zsh_user_path $path)
if [[ -f"/opt/homebrew/opt/chruby/share/chruby/chruby.sh" ]]; then
source "/opt/homebrew/opt/chruby/share/chruby/chruby.sh"
fi
My /etc/zshrc
is stock from macOS:
/etc/zshrc
We cannot always specify
-i
because that would assume you are always running in an interactive shell, which might not always be the case (ex: runningchruby-exec
in a cronjob).
Yeah, agreed. This seems like more of a defect in the zsh conventions, but that isn't something we can really change.
If zsh kept the same convention as ~/.bashrc
(minimal, always run) vs ~/.bash_profile
(more "bloat", for interactive shells only), then we could have just always used non-interactive shells, and rely on the path being set.
But since most people set their $PATH
in ~/.zshrc
... welp, idk what we can do to reasonably handle that.
I'm also totally confused as to what --head
does to make this work, that 0.38.0
didn't.
Also note that chruby-0.3.9 was indeed released 2014-11-23. GitHub releases are separate from the git tags, and I didn't start adding GitHub releases for git tags until much later.
Ah, that explains that part.
FWIW there is ~/.zshenv
which is always sourced. That's where I do PATH modifications.
And my ~/.zshrc
is then for interative-only stuff like completion, etc.
Hey @eregon,
I agree that's the right approach in the abstract, but regrettably, that's just not the common convention with ZSH.
For example, Homebrew's official installation instructions used to suggest adding to your .zshrc
. They only recently switched to using .zprofile
in Sept 2023. There's a contention between what's "right" and what's most common in people's real-world usage.
To me, the most puzzling part here is why --head
works. I would have expected it to fail with the same issue.
Description
chruby.sh
is typically sourced from~/.zshrc
, which is only run in interactive shells. For non-interactive shells,chruby-exec
callszsh
without the-i
:https://github.com/postmodern/chruby/blob/67192019ccf885b23ffc25c7f40ed64be8d2832e/bin/chruby-exec#L41
This causes the
~/.zshrc
to never be sourced, and thus, forchruby
to be unavailable.Steps To Reproduce
Steps to reproduce the bug:
brew install chruby
Run
chruby-exec
with a non-terminal STDIN. E.g. with:Expected Behavior
Run the command successfully, (in this example,
ruby --version
). It works correctly if you drop theecho "abc" |
:This works fine because it hits this other branch, which include
-i
and runs~/.zshrc
:https://github.com/postmodern/chruby/blob/67192019ccf885b23ffc25c7f40ed64be8d2832e/bin/chruby-exec#L40
This also works on the latest
master
branch, so it looks like it's a packaging/release issue:Actual Behavior
Notes
https://github.com/postmodern/chruby/releases/tag/v0.3.9 was release in April 19, 2023, but for some reason, it doesn't include this change to
chruby-exec
from 2014. I confirmed this in 2 ways:bin/chruby-exec
of thechruby-0.3.9.tar.gz
downloaded right from the release page/opt/homebrew/bin/chruby-exec
installed by homebrew.It looks to me like the release process just didn't package up this file correctly.
Environment