From 11a0ea18335cf1901e5e21c964493e2a233cc058 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 4 Mar 2023 16:42:34 -0800 Subject: [PATCH 1/4] irb: enable global options The --debug and --quiet options weren't working before with the REPL because IRB didn't recognize them. --- Library/Homebrew/dev-cmd/irb.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index 3f032038befe6..011202370308d 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -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 @@ -68,4 +70,13 @@ def irb 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 From 6ab6d7c8eeeb51f2ae24697736d46bd5c16b3859 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 4 Mar 2023 21:18:15 -0800 Subject: [PATCH 2/4] irb: save repl history This enables history for `brew irb` sessions. It saves that history to the repository directory. --- .gitignore | 1 + .irb_config | 8 ++++++++ Library/Homebrew/dev-cmd/irb.rb | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 .irb_config diff --git a/.gitignore b/.gitignore index 05579c2c259bb..1d380aeb76853 100644 --- a/.gitignore +++ b/.gitignore @@ -194,6 +194,7 @@ !/.dockerignore !/.editorconfig !/.gitignore +!/.irb_config !/.yardopts !/.vale.ini !/.shellcheckrc diff --git a/.irb_config b/.irb_config new file mode 100644 index 0000000000000..607743700437f --- /dev/null +++ b/.irb_config @@ -0,0 +1,8 @@ +# Note that we use a non-standard config file name to reduce +# name clashes with other IRB config files like `.irbrc`. + +require 'irb/completion' + +IRB.conf[:SAVE_HISTORY] = 100 +IRB.conf[:HISTORY_FILE] = "#{__dir__}/.irb_history" +IRB.conf[:IRB_NAME] = "brew" diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index 011202370308d..eabeb0943e1c3 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -67,6 +67,8 @@ def irb if args.pry? Pry.start else + ENV["IRBRC"] = (HOMEBREW_REPOSITORY/".irb_config").to_s + IRB.start end end From 9f7ab25af5f857dcaf1fbff488ad9630c2781160 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Mon, 6 Mar 2023 22:37:09 -0800 Subject: [PATCH 3/4] irb: improve pry config The idea here is that the pry session history should be separate for homebrew than the global pry history. We also ignore any .pryrc files so that they don't interfere with this config. --- Library/Homebrew/dev-cmd/irb.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index eabeb0943e1c3..dd1c6bf21ec83 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -54,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 @@ -65,6 +64,11 @@ 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 = (HOMEBREW_REPOSITORY/".pry_history").to_s + Pry.config.memory_size = 100 # max lines to save to history file + Pry.config.prompt_name = "brew" + Pry.start else ENV["IRBRC"] = (HOMEBREW_REPOSITORY/".irb_config").to_s From deabd4a5f9adb3fa51ac732c86610c700b52e96d Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Tue, 7 Mar 2023 19:04:19 -0800 Subject: [PATCH 4/4] Change history and config file dirs Now both REPL history is written to $HOME. - Pry: $HOME/.brew_pry_history - IRB: $HOME/.brew_irb_history The IRB config file has also been moved to the library directory. --- .irb_config | 8 -------- Library/Homebrew/brew_irbrc | 9 +++++++++ Library/Homebrew/dev-cmd/irb.rb | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) delete mode 100644 .irb_config create mode 100644 Library/Homebrew/brew_irbrc diff --git a/.irb_config b/.irb_config deleted file mode 100644 index 607743700437f..0000000000000 --- a/.irb_config +++ /dev/null @@ -1,8 +0,0 @@ -# Note that we use a non-standard config file name to reduce -# name clashes with other IRB config files like `.irbrc`. - -require 'irb/completion' - -IRB.conf[:SAVE_HISTORY] = 100 -IRB.conf[:HISTORY_FILE] = "#{__dir__}/.irb_history" -IRB.conf[:IRB_NAME] = "brew" diff --git a/Library/Homebrew/brew_irbrc b/Library/Homebrew/brew_irbrc new file mode 100644 index 0000000000000..e41311ada7991 --- /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 dd1c6bf21ec83..0fef03e89a6fb 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -65,13 +65,13 @@ 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 = (HOMEBREW_REPOSITORY/".pry_history").to_s + 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_REPOSITORY/".irb_config").to_s + ENV["IRBRC"] = (HOMEBREW_LIBRARY_PATH/"brew_irbrc").to_s IRB.start end