Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignore_empty_commands setting. #773

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gabrieldeal
Copy link

Add ignore_empty_commands boolean setting. It defaults to false, which causes an empty command to repeat the last command (the current behavior). If true, an empty command is a no-op.

My implementation differs from what I suggested in issue #700 because it seemed more self-documenting as a boolean setting. Also if I used an enum setting instead, I doubt a third value would ever be added, so the flexibility of an enum would provide no benefit. But I am happy to switch it back to the enum setting that I initially proposed if that is what you prefer!

Fixes #700

Demo

When the setting is false

$ cat ~/.byebugrc
set histfile /home/gabrielx/byebug.history
#set ignore_empty_commands true
$
$ bundle exec ./test.rb

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
=>  8: sleep 2.1
    9: debugger
   10:
   11: sleep 2.2
   12: debugger
(byebug) c

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
    8: sleep 2.1
    9: debugger
   10:
=> 11: sleep 2.2
   12: debugger
(byebug)

[21, 30] in /home/gabrielx/.rvm/gems/ruby-2.5.3/gems/bundler-2.2.0.rc.2/lib/bundler/cli.rb
   21:     }.freeze
   22:
   23:     def self.start(*)
   24:       super
   25:     ensure
=> 26:       Bundler::SharedHelpers.print_major_deprecations!
   27:     end
   28:
   29:     def self.dispatch(*)
   30:       super do |i|
(byebug)
$

When the setting is true

$ cat ~/.byebugrc
set histfile /home/gabrielx/byebug.history
set ignore_empty_commands true
$
$ bundle exec ./test.rb

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
=>  8: sleep 2.1
    9: debugger
   10:
   11: sleep 2.2
   12: debugger
(byebug) c

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
    8: sleep 2.1
    9: debugger
   10:
=> 11: sleep 2.2
   12: debugger
(byebug)
(byebug)
(byebug) c

[21, 30] in /home/gabrielx/.rvm/gems/ruby-2.5.3/gems/bundler-2.2.0.rc.2/lib/bundler/cli.rb
   21:     }.freeze
   22:
   23:     def self.start(*)
   24:       super
   25:     ensure
=> 26:       Bundler::SharedHelpers.print_major_deprecations!
   27:     end
   28:
   29:     def self.dispatch(*)
   30:       super do |i|
(byebug)
(byebug)
(byebug) c
$

Add the `ignore_empty_commands` boolean setting. It defaults to false, which causes an empty command to repeat the last command (the current behavior). If true, an empty command is a no-op.

I want this setting because I frequently press enter a few times in my Rails server terminal (to put a vertical space in the log entries printed to stdout) and then later I try to debug some code in the server. When the debugger line is executed, ByeBug reads those newlines and runs the last command (often continue).

Fixes deivid-rodriguez#700

# Demo

## When the setting is false

```
$ cat ~/.byebugrc
set histfile /home/gabrielx/byebug.history
#set ignore_empty_commands true
$
$ bundle exec ./test.rb

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
=>  8: sleep 2.1
    9: debugger
   10:
   11: sleep 2.2
   12: debugger
(byebug) c

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
    8: sleep 2.1
    9: debugger
   10:
=> 11: sleep 2.2
   12: debugger
(byebug)

[21, 30] in /home/gabrielx/.rvm/gems/ruby-2.5.3/gems/bundler-2.2.0.rc.2/lib/bundler/cli.rb
   21:     }.freeze
   22:
   23:     def self.start(*)
   24:       super
   25:     ensure
=> 26:       Bundler::SharedHelpers.print_major_deprecations!
   27:     end
   28:
   29:     def self.dispatch(*)
   30:       super do |i|
(byebug)
$
```

### When the setting is true
```
$ cat ~/.byebugrc
set histfile /home/gabrielx/byebug.history
set ignore_empty_commands true
$
$ bundle exec ./test.rb

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
=>  8: sleep 2.1
    9: debugger
   10:
   11: sleep 2.2
   12: debugger
(byebug) c

[3, 12] in /home/gabrielx/projects/byebug/test.rb
    3:
    4: require 'byebug'
    5:
    6: debugger
    7:
    8: sleep 2.1
    9: debugger
   10:
=> 11: sleep 2.2
   12: debugger
(byebug)
(byebug)
(byebug) c

[21, 30] in /home/gabrielx/.rvm/gems/ruby-2.5.3/gems/bundler-2.2.0.rc.2/lib/bundler/cli.rb
   21:     }.freeze
   22:
   23:     def self.start(*)
   24:       super
   25:     ensure
=> 26:       Bundler::SharedHelpers.print_major_deprecations!
   27:     end
   28:
   29:     def self.dispatch(*)
   30:       super do |i|
(byebug)
(byebug)
(byebug) c
$
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting to disable using the last command if the current command is empty
2 participants