Skip to content

Conversation

@Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Dec 12, 2025

Sometimes I want to be able to interact with Homebrew ruby and bundle directly to do various things.

This PR adds a --ruby option to brew sh that starts an interactive shell with Homebrew's ruby and bundle set up so you can run bundle exec and other commands directly.

$ bundle exec rubocop --version
Source locally installed gems is ignoring #<Bundler::StubSpecification name=vernier version=1.9.0 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=stackprof version=0.2.27 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=ruby-prof version=1.7.2 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=redcarpet version=3.6.1 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=rbs version=4.0.0.dev.4 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=racc version=1.8.1 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=pycall version=1.5.2 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=prism version=1.6.0 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.16.0 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=bigdecimal version=3.3.1 platform=ruby> because it is missing extensions
bundler: failed to load command: rubocop (/opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.4.0/bin/rubocop)
/Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/rubygems_integration.rb:236:in 'block in Gem.replace_bin_path': can't find executable rubocop for gem rubocop. rubocop is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/site_ruby/3.4.0/rubygems.rb:237:in 'Gem.find_and_activate_spec_for_exe'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/site_ruby/3.4.0/rubygems.rb:318:in 'Gem.activate_bin_path'
	from /opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.4.0/bin/rubocop:25:in '<top (required)>'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/cli/exec.rb:61:in 'Kernel.load'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/cli/exec.rb:61:in 'Bundler::CLI::Exec#kernel_load'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/cli/exec.rb:24:in 'Bundler::CLI::Exec#run'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/cli.rb:494:in 'Bundler::CLI#exec'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/cli.rb:35:in 'Bundler::CLI.dispatch'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/cli.rb:29:in 'Bundler::CLI.start'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/exe/bundle:28:in 'block in <top (required)>'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/lib/bundler/friendly_errors.rb:118:in 'Bundler.with_friendly_errors'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/gems/3.4.0/gems/bundler-4.0.0/exe/bundle:20:in '<top (required)>'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/site_ruby/3.4.0/rubygems.rb:303:in 'Kernel#load'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/lib/ruby/site_ruby/3.4.0/rubygems.rb:303:in 'Gem.activate_and_load_bin_path'
	from /Users/rylanpolster/.rbenv/versions/3.4.7/bin/bundle:25:in '<main>'

$ brew sh --ruby --cmd='bundle exec rubocop --version'
1.81.7

Copilot AI review requested due to automatic review settings December 12, 2025 17:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new brew ruby-sh developer command that provides an interactive shell configured with Homebrew's Ruby environment, making it easier to work with Homebrew's development tools like RuboCop, Sorbet, and RSpec. It also fixes zsh shell configuration by ensuring .zshenv is properly symlinked when using custom ZDOTDIR settings.

  • Adds ruby-sh command for interactive Ruby environment shell access
  • Includes support for non-interactive execution via -c flag and file arguments
  • Updates shell utility to symlink .zshenv for proper zsh environment initialization

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
Library/Homebrew/dev-cmd/ruby-sh.rb New command implementation that sets up Ruby environment and starts an interactive or non-interactive shell
Library/Homebrew/test/dev-cmd/ruby-sh_spec.rb Basic test file covering argument parsing for the new command
Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/ruby_sh.rbi Auto-generated Sorbet type signatures for the RubySh command class
Library/Homebrew/utils/shell.rb Adds .zshenv to the list of symlinked files when using custom ZDOTDIR to ensure proper zsh initialization
Files not reviewed (1)
  • Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/ruby_sh.rbi: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of overlap with brew sh here. Maybe we can just add an extra flag to brew sh to get the desired behaviour here?

Alternatively, we should consider extracting the common code between this and sh.rb elsewhere so they can remain identical in sh.rb and ruby-sh.rb.

@MikeMcQuaid
Copy link
Member

There's a lot of overlap with brew sh here. Maybe we can just add an extra flag to brew sh to get the desired behaviour here?

@Rylan12 I agree with @carlocab here (good idea @carlocab!). A flag makes sense for that I think.

@Rylan12 Rylan12 changed the title Add ruby-sh command Add --ruby option to brew sh Dec 13, 2025
@Rylan12 Rylan12 force-pushed the add-ruby-sh-command branch from e52575c to f7e83a7 Compare December 13, 2025 02:19
@Rylan12
Copy link
Member Author

Rylan12 commented Dec 13, 2025

Good suggestion! I changed this to be a --ruby option to brew sh, instead

@Rylan12 Rylan12 force-pushed the add-ruby-sh-command branch from f7e83a7 to 4f1551b Compare December 13, 2025 02:24
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Dec 13, 2025
Merged via the queue into main with commit 3d617b8 Dec 13, 2025
37 checks passed
@MikeMcQuaid MikeMcQuaid deleted the add-ruby-sh-command branch December 13, 2025 13:17
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

Successfully merging this pull request may close these issues.

4 participants