chruby
chruby copied to clipboard
Non-interactive `chruby-exec` fails with `zsh:1: command not found: chruby`
Description
chruby.sh
is typically sourced from ~/.zshrc
, which is only run in interactive shells. For non-interactive shells, chruby-exec
calls zsh
without the -i
:
https://github.com/postmodern/chruby/blob/67192019ccf885b23ffc25c7f40ed64be8d2832e/bin/chruby-exec#L41
This causes the ~/.zshrc
to never be sourced, and thus, for chruby
to be unavailable.
Steps To Reproduce
Steps to reproduce the bug:
-
Install the latest release (0.39.0 right now) with
brew install chruby
-
Run
chruby-exec
with a non-terminal STDIN. E.g. with:echo "abc" | chruby-exec "ruby-3.3.0" -- ruby --version
Expected Behavior
Run the command successfully, (in this example, ruby --version
). It works correctly if you drop the echo "abc" |
:
$ chruby-exec "ruby-3.3.0" -- ruby --version
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
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:
$ brew uninstall chruby && brew install chruby --head
$ echo "abc" | chruby-exec "ruby-3.3.0" -- ruby --version
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Actual Behavior
$ echo "abc" | chruby-exec "ruby-3.3.0" -- ruby --version
zsh:1: command not found: chruby
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:
- Inspecting
bin/chruby-exec
of thechruby-0.3.9.tar.gz
downloaded right from the release page - Inspecting
/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
$ bash --version
GNU bash, version 5.2.26(1)-release (aarch64-apple-darwin23.2.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ zsh --version
zsh 5.9 (x86_64-apple-darwin23.0)
$ chruby --version
Untitled 10.sh: line 8: chruby: command not found
$ ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
$ gem --version
3.0.3.1
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3.1
- RUBY VERSION: 2.6.10 (2022-04-12 patchlevel 210) [universal.arm64e-darwin23]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/Alex/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /Users/Alex/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-23
- GEM PATHS:
- /Library/Ruby/Gems/2.6.0
- /Users/Alex/.gem/ruby/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /opt/homebrew/bin
- /Users/Alex/.cargo/bin
- /usr/local/bin
- /System/Cryptexes/App/usr/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
- /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
- /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
- /Library/Apple/usr/bin
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/lib
- /Users/Alex/.antigen/bundles/marlonrichert/zsh-autocomplete-main
- /Users/Alex/.antigen/bundles/marlonrichert/zsh-autocomplete-main/functions
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/git
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/last-working-dir
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/macos
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/sudo
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/alias-finder
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/rust
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/colored-man-pages
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/command-not-found
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/common-aliases
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/dircycle
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/encode64
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/extract
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/jsontools
- /Users/Alex/.antigen/bundles/robbyrussell/oh-my-zsh/plugins/swiftpm
- /Users/Alex/.antigen/bundles/dracula/zsh-syntax-highlighting
- /Users/Alex/.antigen/bundles/zsh-users/zsh-syntax-highlighting
- /Applications/CodeRunner.app/Contents/SharedSupport/Developer/bin