Merge pull request #14892 from apainintheneck/irb-improvements

`brew irb` improvements
This commit is contained in:
Mike McQuaid 2023-03-08 12:46:56 +00:00 committed by GitHub
commit e5c0fb4ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

1
.gitignore vendored
View File

@ -194,6 +194,7 @@
!/.dockerignore
!/.editorconfig
!/.gitignore
!/.irb_config
!/.yardopts
!/.vale.ini
!/.shellcheckrc

View File

@ -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"

View File

@ -48,6 +48,8 @@ module Homebrew
# 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
@ -64,7 +66,6 @@ module Homebrew
if args.pry?
Homebrew.install_gem_setup_path! "pry"
require "pry"
Pry.config.prompt_name = "brew"
else
require "irb"
end
@ -75,9 +76,25 @@ module Homebrew
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