Module: RuVim::Git::Grep
- Defined in:
- lib/ruvim/git/grep.rb
Defined Under Namespace
Modules: HandlerMethods
Class Method Summary collapse
-
.parse_location(line) ⇒ Object
Parse a git grep output line (file:line:content).
-
.run(file_path, args: []) ⇒ Object
Run git grep -n with extra args.
Class Method Details
.parse_location(line) ⇒ Object
Parse a git grep output line (file:line:content). Returns [filename, line_number] or nil.
27 28 29 30 31 32 33 34 |
# File 'lib/ruvim/git/grep.rb', line 27 def parse_location(line) return nil if line.empty? || line == "--" m = line.match(/\A(.+?):(\d+):/) return nil unless m [m[1], m[2].to_i] end |
.run(file_path, args: []) ⇒ Object
Run git grep -n with extra args. Returns [lines, root, error_message].
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruvim/git/grep.rb', line 12 def run(file_path, args: []) root, err = Git.repo_root(file_path) return [nil, nil, err] unless root cmd = ["git", "grep", "-n", *args] out, err, status = Open3.capture3(*cmd, chdir: root) # git grep exits 1 when no matches found (not an error) unless status.success? || status.exitstatus == 1 return [nil, nil, err.strip] end [out.lines(chomp: true), root, nil] end |