Class: GrepProfile

Inherits:
ZoomProfile show all
Defined in:
lib/grep_profile.rb

Instance Attribute Summary

Attributes inherited from ZoomProfile

#taggable

Instance Method Summary collapse

Methods inherited from ZoomProfile

#append, #flags, from_json, #info, #operator, #prepend, #to_s

Constructor Details

#initialize(operator = nil, flags = [ "--color=always", "-EHIinR", "--exclude-dir=.bzr", "--exclude-dir=.git", "--exclude-dir=.svn" ].join(" ").strip, envprepend = "", append = ".") ⇒ GrepProfile

Returns a new instance of GrepProfile.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/grep_profile.rb', line 33

def initialize(
    operator = nil,
    flags = [
        "--color=always",
        "-EHIinR",
        "--exclude-dir=.bzr",
        "--exclude-dir=.git",
        "--exclude-dir=.svn"
    ].join(" ").strip,
    envprepend = "",
    append = "."
)
    super("grep", flags, envprepend, append)
    @taggable = true
end

Instance Method Details

#colorsObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/grep_profile.rb', line 5

def colors
    [
        'GREP_COLORS="',
        "fn=1;32:",
        "ln=0;37:",
        "ms=47;1;30:",
        "mc=47;1;30:",
        "sl=:cx=:bn=:se=",
        '"'
    ].join.strip
end

#exe(args, pattern) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/grep_profile.rb', line 17

def exe(args, pattern)
    # Emulate ag/ack as much as possible
    if (pattern.nil? || pattern.empty?)
        system(
            "#{self.to_s} #{args} #{self.append} | " \
            "sed \"s|\\[K[:-]|\\[K\\n|\" | #{@pager}"
        )
    else
        system(
            "#{self.to_s} #{args} #{pattern.shellescape} " \
            "#{self.append} | sed \"s|\\[K[:-]|\\[K\\n|\" | " \
            "#{@pager}"
        )
    end
end