Skip to content

Commit

Permalink
Merge pull request #14892 from apainintheneck/irb-improvements
Browse files Browse the repository at this point in the history
`brew irb` improvements
  • Loading branch information
MikeMcQuaid committed Mar 8, 2023
2 parents b180133 + deabd4a commit e5c0fb4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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 @@ -48,6 +48,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 @@ -64,7 +66,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 @@ -75,9 +76,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
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

0 comments on commit e5c0fb4

Please sign in to comment.