diff --git a/.gitignore b/.gitignore index 05579c2c25..1d380aeb76 100644 --- a/.gitignore +++ b/.gitignore @@ -194,6 +194,7 @@ !/.dockerignore !/.editorconfig !/.gitignore +!/.irb_config !/.yardopts !/.vale.ini !/.shellcheckrc diff --git a/Library/Homebrew/brew_irbrc b/Library/Homebrew/brew_irbrc new file mode 100644 index 0000000000..e41311ada7 --- /dev/null +++ b/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" diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index 7d7c5a81ae..45e9abc27a 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -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