From 99bd25d6d88022b8fa501fc62203e13a9fc7dc1d Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 3 Dec 2022 17:35:38 +0000 Subject: [PATCH] Allow using IRB_USE_AUTOCOMPLETE=false to disable autocompletion Currently, the only 2 ways to disable autocompletion are: 1. Create `.irbrc` and set `IRB.conf[:USE_AUTOCOMPLETE] = false` 2. Add the `--noautocomplete` flag when using the `irb` executable Both of them are less convenient than setting a env var and are lesser known to devs. And given the number of problems the autocompletion has (see #445), I think we should allow disabling it with a simple `IRB_USE_AUTOCOMPLETE=false`. --- lib/irb/init.rb | 2 +- test/irb/test_init.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/irb/init.rb b/lib/irb/init.rb index dd888f372..8e745adbe 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -45,7 +45,7 @@ def IRB.init_config(ap_path) @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod) @CONF[:USE_COLORIZE] = (nc = ENV['NO_COLOR']).nil? || nc.empty? - @CONF[:USE_AUTOCOMPLETE] = true + @CONF[:USE_AUTOCOMPLETE] = !(ENV.fetch("IRB_USE_AUTOCOMPLETE", "true") == "false") @CONF[:INSPECT_MODE] = true @CONF[:USE_TRACER] = false @CONF[:USE_LOADER] = false diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index 9591de158..d9e338da8 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -96,6 +96,30 @@ def test_no_color_environment_variable IRB.conf[:USE_COLORIZE] = orig_use_colorize end + def test_use_autocomplete_environment_variable + orig_use_autocomplete_env = ENV['IRB_USE_AUTOCOMPLETE'] + orig_use_autocomplete_conf = IRB.conf[:USE_AUTOCOMPLETE] + + ENV['IRB_USE_AUTOCOMPLETE'] = nil + IRB.setup(__FILE__) + assert IRB.conf[:USE_AUTOCOMPLETE] + + ENV['IRB_USE_AUTOCOMPLETE'] = '' + IRB.setup(__FILE__) + assert IRB.conf[:USE_AUTOCOMPLETE] + + ENV['IRB_USE_AUTOCOMPLETE'] = 'false' + IRB.setup(__FILE__) + refute IRB.conf[:USE_AUTOCOMPLETE] + + ENV['IRB_USE_AUTOCOMPLETE'] = 'true' + IRB.setup(__FILE__) + assert IRB.conf[:USE_AUTOCOMPLETE] + ensure + ENV["IRB_USE_AUTOCOMPLETE"] = orig_use_autocomplete_env + IRB.conf[:USE_AUTOCOMPLETE] = orig_use_autocomplete_conf + end + def test_noscript argv = %w[--noscript -- -f] IRB.setup(eval("__FILE__"), argv: argv)