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

brew irb improvements #14892

Merged
merged 4 commits into from Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -194,6 +194,7 @@
!/.dockerignore
!/.editorconfig
!/.gitignore
!/.irb_config
!/.yardopts
!/.vale.ini
!/.shellcheckrc
Expand Down
9 changes: 9 additions & 0 deletions Library/Homebrew/brew_irbrc
@@ -0,0 +1,9 @@
# Note: that we use a non-standard config file name to reduce
# name clashes with other IRB config files like `.irbrc`.
# Note #2: This doesn't work with system Ruby for some reason.

require 'irb/completion'

IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{Dir.home}/.brew_irb_history"
IRB.conf[:IRB_NAME] = "brew"
19 changes: 18 additions & 1 deletion Library/Homebrew/dev-cmd/irb.rb
Expand Up @@ -39,6 +39,8 @@ def irb
# work around IRB modifying ARGV.
args = irb_args.parse(ARGV.dup.freeze)

clean_argv

if args.examples?
puts <<~EOS
'v8'.f # => instance of the v8 formula
Expand All @@ -52,7 +54,6 @@ def irb
if args.pry?
Homebrew.install_gem_setup_path! "pry"
require "pry"
Pry.config.prompt_name = "brew"
else
require "irb"
end
Expand All @@ -63,9 +64,25 @@ def irb

ohai "Interactive Homebrew Shell", "Example commands available with: `brew irb --examples`"
if args.pry?
Pry.config.should_load_rc = false # skip loading .pryrc
Copy link
Member

Choose a reason for hiding this comment

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

This may be unexpected behaviour. May want to check with any @Homebrew/brew folks who use pry

Pry.config.history_file = "#{Dir.home}/.brew_pry_history"
Pry.config.memory_size = 100 # max lines to save to history file
Pry.config.prompt_name = "brew"

Pry.start
else
ENV["IRBRC"] = (HOMEBREW_LIBRARY_PATH/"brew_irbrc").to_s

IRB.start
end
end

# Remove the `--debug`, `--verbose` and `--quiet` options which cause problems
# for IRB and have already been parsed by the CLI::Parser.
def clean_argv
global_options = Homebrew::CLI::Parser
.global_options
.flat_map { |options| options[0..1] }
ARGV.reject! { |arg| global_options.include?(arg) }
end
end