Skip to content

Commit

Permalink
Allow disabling autocompletion with IRB_USE_AUTOCOMPLETE=false (#469)
Browse files Browse the repository at this point in the history
* 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`.

* Mention some env var configs in the README
  • Loading branch information
st0012 authored Dec 6, 2022
1 parent 8e6f90b commit a6648bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ The following commands are available on IRB.
* `break`, `delete`, `next`, `step`, `continue`, `finish`, `backtrace`, `info`, `catch`
* Start the debugger of debug.gem and run the command on it.

## Configuration

### Environment Variables

- `NO_COLOR`: Assigning a value to it disables IRB's colorization.
- `IRB_USE_AUTOCOMPLETE`: Setting it to `false` disables IRB's autocompletion.
- `EDITOR`: Its value would be used to open files by the `edit` command.
- `IRBRC`: The file specified would be evaluated as IRB's rc-file.

## Documentation

https://docs.ruby-lang.org/en/master/IRB.html
Expand Down
2 changes: 1 addition & 1 deletion lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/irb/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a6648bf

Please sign in to comment.