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

Implement history command #761

Merged
merged 13 commits into from
Dec 2, 2023
Merged

Conversation

garyhtou
Copy link
Contributor

@garyhtou garyhtou commented Nov 13, 2023

This PR adds the history command (aliased as hist) which provides a list of previous IRB inputs. This supports multiline inputs but truncates them to two lines. Lines are displayed in reverse to show the most recent inputs first.

This command also supports grep (-g or -G option); similar to the ls command.

image

Closes #751

Lists IRB input history with indices. Also aliased as `hist`.
lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
@st0012 st0012 added the enhancement New feature or request label Nov 23, 2023
@st0012
Copy link
Member

st0012 commented Nov 29, 2023

@garyhtou 👋 I think once you addressed these 2 feedback, we'll be very close to merging this PR and make it part of Ruby 3.3 😉

@garyhtou
Copy link
Contributor Author

Oops, sorry for leaving this hanging. Thanks for the ping!

I'll wrap this up later tonight :)

lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
@garyhtou
Copy link
Contributor Author

It appears the CI failure might be unrelated

#790

lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
lib/irb/cmd/history.rb Outdated Show resolved Hide resolved
Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you 👍

@tompng tompng merged commit 3f9eacb into ruby:master Dec 2, 2023
24 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Dec 2, 2023
(ruby/irb#761)

* Implement `history` command

Lists IRB input history with indices. Also aliased as `hist`.

* Add tests for `history` command

* Address feedback: `puts` with multiple arguments instead of `join`ing

* Address feedback: Handle nil from splitting an empty input string

* Refactor line truncation

* Add `-g` grep option to `history` command

* Add `history` command to README

* Remove unused `*args` parameter

* Allow spaces to be included in grep

* Allow `/` to be included in grep regex

* Handle `input` being an empty string

* Exclude "#{index}: " from matching the grep regex

* Add new line after joining

ruby/irb@3f9eacbfa9
@garyhtou garyhtou deleted the garyhtou/hist-command branch December 2, 2023 06:05
@garyhtou
Copy link
Contributor Author

garyhtou commented Dec 2, 2023

Thank you @tompng and @st0012 for helping guide me through this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

Support hist command
3 participants