Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def initialize(workspace = nil, input_method = nil)
@context = Context.new(self, workspace, input_method)
@context.main.extend ExtendCommandBundle
@context.command_aliases.each do |alias_name, cmd_name|
next if @context.symbol_alias(alias_name)
@context.main.install_alias_method(alias_name, cmd_name)
end
@signal_status = :IN_IRB
Expand Down
9 changes: 9 additions & 0 deletions lib/irb/cmd/ls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ module IRB

module ExtendCommand
class Ls < Nop
def self.transform_args(args)
if match = args&.match(/\A(?<args>.+\s|)(-g|-G)\s+(?<grep>[^\s]+)\s*\n\z/)
args = match[:args]
"#{args}#{',' unless args.chomp.empty?} grep: /#{match[:grep]}/"
else
args
end
end

def execute(*arg, grep: nil)
o = Output.new(grep: grep)

Expand Down
38 changes: 38 additions & 0 deletions test/irb/test_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,44 @@ def test_ls
assert_match(/C.methods:\s+m5\n/m, out)
end

def test_ls_grep
pend if RUBY_ENGINE == 'truffleruby'
out, err = execute_lines("ls 42\n")
assert_empty err
assert_match(/times/, out)
assert_match(/polar/, out)

[
"ls 42, grep: /times/\n",
"ls 42 -g times\n",
"ls 42 -G times\n",
].each do |line|
out, err = execute_lines(line)
assert_empty err
assert_match(/times/, out)
assert_not_match(/polar/, out)
end
end

def test_ls_grep_empty
pend if RUBY_ENGINE == 'truffleruby'
out, err = execute_lines("ls\n")
assert_empty err
assert_match(/whereami/, out)
assert_match(/show_source/, out)

[
"ls grep: /whereami/\n",
"ls -g whereami\n",
"ls -G whereami\n",
].each do |line|
out, err = execute_lines(line)
assert_empty err
assert_match(/whereami/, out)
assert_not_match(/show_source/, out)
end
end

def test_ls_with_no_singleton_class
out, err = execute_lines(
"ls 42",
Expand Down