ruby-zoom 4.7.5 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/z +108 -50
- data/bin/zc +108 -50
- data/bin/zf +108 -50
- data/bin/zg +108 -50
- data/bin/zl +108 -50
- data/bin/zr +108 -50
- data/lib/zoom.rb +89 -26
- data/lib/zoom/cache.rb +10 -9
- data/lib/zoom/cache/result.rb +3 -3
- data/lib/zoom/config.rb +15 -6
- data/lib/zoom/editor.rb +8 -4
- data/lib/zoom/error.rb +1 -0
- data/lib/zoom/error/regex_not_provided.rb +5 -0
- data/lib/zoom/profile.rb +62 -90
- data/lib/zoom/profile/ack.rb +35 -10
- data/lib/zoom/profile/ag.rb +21 -5
- data/lib/zoom/profile/find.rb +48 -4
- data/lib/zoom/profile/grep.rb +25 -5
- data/lib/zoom/profile/passwords.rb +5 -13
- data/lib/zoom/profile/pt.rb +21 -5
- data/lib/zoom/profile/rg.rb +51 -0
- data/lib/zoom/profile/unsafe_c.rb +32 -30
- data/lib/zoom/profile/unsafe_java.rb +15 -28
- data/lib/zoom/profile/unsafe_js.rb +5 -12
- data/lib/zoom/profile/unsafe_php.rb +48 -55
- data/lib/zoom/profile/unsafe_python.rb +16 -24
- data/lib/zoom/profile/unsafe_ruby.rb +16 -25
- data/lib/zoom/profile_manager.rb +50 -16
- data/lib/zoom/security_profile.rb +60 -5
- data/lib/zoom/wish/edit_wish.rb +4 -4
- data/lib/zoom/wish/editor_wish.rb +2 -8
- metadata +14 -12
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c3abef8eb66e1700c95fcc0b7662e76295017f26
         | 
| 4 | 
            +
              data.tar.gz: 3afe4b3b2d8aa3799f64f95c8d94015e059ed1a7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b718901f854caeb59dff28fb8c61a87d45fa45256d304c72aa40475caae1c79ce379580486874c32192aa265a1d3b3737c9636133ee7dd1a61922fe19735f5f5
         | 
| 7 | 
            +
              data.tar.gz: 8a509d96696691b66d09d8bb372e0017c5a0aedfa65f0cf5f1c72689a31c92ab2b713e313e00cc1bc02009e98b073681c8cadce041ed32ac82185afbc37dbe0a
         | 
    
        data/bin/z
    CHANGED
    
    | @@ -20,40 +20,70 @@ def parse(args) | |
| 20 20 | 
             
                options = Hash.new
         | 
| 21 21 | 
             
                options["action"] = "exec"
         | 
| 22 22 | 
             
                options["cache_file"] = nil
         | 
| 23 | 
            +
                options["debug"] = false
         | 
| 24 | 
            +
                options["passthru"] = ""
         | 
| 25 | 
            +
                options["tool"] = nil
         | 
| 23 26 | 
             
                options["translate_flags"] = Hash.new
         | 
| 24 27 | 
             
                options["use"] = nil
         | 
| 25 28 | 
             
                options["verbose"] = false
         | 
| 26 29 |  | 
| 27 30 | 
             
                info = [
         | 
| 28 | 
            -
                    "Do you like to search through code using ag, ack, grep,  | 
| 29 | 
            -
                    " | 
| 30 | 
            -
                    "to  | 
| 31 | 
            -
                    "search results in your editor of choice. | 
| 32 | 
            -
                    "large code-bases, it can be a pain to have | 
| 33 | 
            -
                    "find the filename of each result. Zoom prints | 
| 34 | 
            -
                    "in front of each result that  | 
| 35 | 
            -
                    "you can quickly open that tag number with Zoom to jump",
         | 
| 31 | 
            +
                    "Do you like to search through code using ag, ack, grep, pt,",
         | 
| 32 | 
            +
                    "or rg? Good! This tool is for you! Zoom adds some",
         | 
| 33 | 
            +
                    "convenience to grep-like search tools by allowing you to",
         | 
| 34 | 
            +
                    "quickly open your search results in your editor of choice.",
         | 
| 35 | 
            +
                    "When looking at large code-bases, it can be a pain to have",
         | 
| 36 | 
            +
                    "to scroll to find the filename of each result. Zoom prints",
         | 
| 37 | 
            +
                    "a tag number in front of each result that grep outputs.",
         | 
| 38 | 
            +
                    "Then you can quickly open that tag number with Zoom to jump",
         | 
| 36 39 | 
             
                    "straight to the source. Zoom is even persistent across all",
         | 
| 37 40 | 
             
                    "your sessions! You can search in one terminal and jump to a",
         | 
| 38 41 | 
             
                    "tag in another terminal from any directory!"
         | 
| 39 42 | 
             
                ].join(" ")
         | 
| 40 43 |  | 
| 44 | 
            +
                passthru = Array.new
         | 
| 45 | 
            +
             | 
| 41 46 | 
             
                parser = OptionParser.new do |opts|
         | 
| 42 47 | 
             
                    opts.summary_width = 25
         | 
| 43 48 |  | 
| 44 49 | 
             
                    opts.banner = [
         | 
| 45 | 
            -
                        "Usage: #{File.basename($0)} [OPTIONS]",
         | 
| 46 | 
            -
                        "[passthru options] [ | 
| 50 | 
            +
                        "Usage: #{File.basename($0)} [OPTIONS] --",
         | 
| 51 | 
            +
                        "[passthru options] [regex] [path1]...[pathN]"
         | 
| 47 52 | 
             
                    ].join(" ")
         | 
| 48 53 |  | 
| 49 54 | 
             
                    opts.on("", "DESCRIPTION")
         | 
| 50 55 |  | 
| 51 | 
            -
                    info.scan(/\S.{0, | 
| 56 | 
            +
                    info.scan(/\S.{0,66}\S(?=\s|$)|\S+/).each do |line|
         | 
| 52 57 | 
             
                        opts.on("    #{line}")
         | 
| 53 58 | 
             
                    end
         | 
| 54 59 |  | 
| 55 60 | 
             
                    opts.on("", "OPTIONS")
         | 
| 56 61 |  | 
| 62 | 
            +
                    opts.on(
         | 
| 63 | 
            +
                        "-A",
         | 
| 64 | 
            +
                        "--after-context=NUM",
         | 
| 65 | 
            +
                        "Show NUM lines after each match"
         | 
| 66 | 
            +
                    ) do |num|
         | 
| 67 | 
            +
                        passthru.push("-A #{num}")
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    opts.on(
         | 
| 71 | 
            +
                        "-a",
         | 
| 72 | 
            +
                        "--all",
         | 
| 73 | 
            +
                        "Search all files (including binaries and VCS",
         | 
| 74 | 
            +
                        "ignored files)"
         | 
| 75 | 
            +
                    ) do
         | 
| 76 | 
            +
                        options["translate_flags"]["all"] = ""
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                    opts.on(
         | 
| 80 | 
            +
                        "-B",
         | 
| 81 | 
            +
                        "--before-context=NUM",
         | 
| 82 | 
            +
                        "Show NUM lines before each match"
         | 
| 83 | 
            +
                    ) do |num|
         | 
| 84 | 
            +
                        passthru.push("-B #{num}")
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
             | 
| 57 87 | 
             
                    opts.on("-c", "--cache", "Show previous results") do
         | 
| 58 88 | 
             
                        options["action"] = "cache"
         | 
| 59 89 | 
             
                    end
         | 
| @@ -66,10 +96,38 @@ def parse(args) | |
| 66 96 | 
             
                        options["cache_file"] = file
         | 
| 67 97 | 
             
                    end
         | 
| 68 98 |  | 
| 99 | 
            +
                    opts.on(
         | 
| 100 | 
            +
                        "-C",
         | 
| 101 | 
            +
                        "--context=NUM",
         | 
| 102 | 
            +
                        "Show NUM lines before and after each match"
         | 
| 103 | 
            +
                    ) do |num|
         | 
| 104 | 
            +
                        passthru.push("-C #{num}")
         | 
| 105 | 
            +
                    end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                    opts.on(
         | 
| 108 | 
            +
                        "-d",
         | 
| 109 | 
            +
                        "--debug",
         | 
| 110 | 
            +
                        "Show command that would be run (but don't run)"
         | 
| 111 | 
            +
                    ) do
         | 
| 112 | 
            +
                        options["debug"] = true
         | 
| 113 | 
            +
                    end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                    opts.on("-f", "--follow", "Follow symlinks") do
         | 
| 116 | 
            +
                        options["translate_flags"]["follow"] = ""
         | 
| 117 | 
            +
                    end
         | 
| 118 | 
            +
             | 
| 69 119 | 
             
                    opts.on("--find", "Use built-in find profile") do
         | 
| 70 120 | 
             
                        options["use"] = "find"
         | 
| 71 121 | 
             
                    end
         | 
| 72 122 |  | 
| 123 | 
            +
                    opts.on(
         | 
| 124 | 
            +
                        "--force-tool=TOOL",
         | 
| 125 | 
            +
                        "Use the specified tool (with applicable",
         | 
| 126 | 
            +
                        "profiles)"
         | 
| 127 | 
            +
                    ) do |tool|
         | 
| 128 | 
            +
                        options["tool"] = tool
         | 
| 129 | 
            +
                    end
         | 
| 130 | 
            +
             | 
| 73 131 | 
             
                    opts.on(
         | 
| 74 132 | 
             
                        "-g",
         | 
| 75 133 | 
             
                        "--go=NUM",
         | 
| @@ -86,11 +144,11 @@ def parse(args) | |
| 86 144 |  | 
| 87 145 | 
             
                    opts.on(
         | 
| 88 146 | 
             
                        "-i",
         | 
| 89 | 
            -
                        "--ignore= | 
| 90 | 
            -
                        "Ignore files/directories matching  | 
| 91 | 
            -
                    ) do | | 
| 147 | 
            +
                        "--ignore=GLOB",
         | 
| 148 | 
            +
                        "Ignore files/directories matching GLOB"
         | 
| 149 | 
            +
                    ) do |regex|
         | 
| 92 150 | 
             
                        options["translate_flags"]["ignore"] ||= Array.new
         | 
| 93 | 
            -
                        options["translate_flags"]["ignore"].push( | 
| 151 | 
            +
                        options["translate_flags"]["ignore"].push(regex)
         | 
| 94 152 | 
             
                    end
         | 
| 95 153 |  | 
| 96 154 | 
             
                    opts.on("-l", "--list", "List profiles") do
         | 
| @@ -98,11 +156,12 @@ def parse(args) | |
| 98 156 | 
             
                    end
         | 
| 99 157 |  | 
| 100 158 | 
             
                    opts.on(
         | 
| 101 | 
            -
                        "-- | 
| 102 | 
            -
                        "Read  | 
| 159 | 
            +
                        "--regex-file=FILE",
         | 
| 160 | 
            +
                        "Read regexes from lines of file (treated as",
         | 
| 161 | 
            +
                        "OR)"
         | 
| 103 162 | 
             
                    ) do |file|
         | 
| 104 | 
            -
                         | 
| 105 | 
            -
                        options[" | 
| 163 | 
            +
                        regexes = File.open(file).read.split(/[\n\r]+/)
         | 
| 164 | 
            +
                        options["regex"] = "(#{regexes.join(")|(")})"
         | 
| 106 165 | 
             
                    end
         | 
| 107 166 |  | 
| 108 167 | 
             
                    opts.on("-r", "--repeat", "Repeat last Zoom command") do
         | 
| @@ -170,23 +229,29 @@ def parse(args) | |
| 170 229 | 
             
                    end
         | 
| 171 230 |  | 
| 172 231 | 
             
                    opts.on("--version", "Show version") do
         | 
| 173 | 
            -
                         | 
| 232 | 
            +
                        __FILE__.match(/ruby-zoom-(\d+\.\d+\.\d+)/) do |m|
         | 
| 233 | 
            +
                            puts m[1]
         | 
| 234 | 
            +
                        end
         | 
| 235 | 
            +
                        exit ZoomExit::GOOD
         | 
| 174 236 | 
             
                    end
         | 
| 175 237 |  | 
| 176 238 | 
             
                    opts.on(
         | 
| 177 239 | 
             
                        "",
         | 
| 178 240 | 
             
                        "EXAMPLES",
         | 
| 179 241 | 
             
                        "    Execute default profile:",
         | 
| 180 | 
            -
                        "    $ z  | 
| 242 | 
            +
                        "    $ z REGEX",
         | 
| 181 243 | 
             
                        "",
         | 
| 182 244 | 
             
                        "    Execute specified profile:",
         | 
| 183 | 
            -
                        "    $ z -u grep  | 
| 245 | 
            +
                        "    $ z -u grep REGEX",
         | 
| 246 | 
            +
                        "",
         | 
| 247 | 
            +
                        "    Pass additional flags to grep profile:",
         | 
| 248 | 
            +
                        "    $ z -u grep -- --line-regexp REGEX",
         | 
| 184 249 | 
             
                        "",
         | 
| 185 | 
            -
                        "     | 
| 186 | 
            -
                        "    $ z  | 
| 250 | 
            +
                        "    Ignore .class files and test related files",
         | 
| 251 | 
            +
                        "    $ z -i \"*.class\" -i \"*test*\" REGEX",
         | 
| 187 252 | 
             
                        "",
         | 
| 188 | 
            -
                        "    Open tags:",
         | 
| 189 | 
            -
                        "    $  | 
| 253 | 
            +
                        "    Open specified tags:",
         | 
| 254 | 
            +
                        "    $ z --go 10,20,30-40"
         | 
| 190 255 | 
             
                    )
         | 
| 191 256 | 
             
                end
         | 
| 192 257 |  | 
| @@ -230,24 +295,23 @@ def parse(args) | |
| 230 295 | 
             
                end
         | 
| 231 296 |  | 
| 232 297 | 
             
                paths = Array.new
         | 
| 233 | 
            -
                 | 
| 234 | 
            -
                while ( | 
| 235 | 
            -
                    paths.push( | 
| 236 | 
            -
                     | 
| 298 | 
            +
                regex = args.delete_at(-1)
         | 
| 299 | 
            +
                while (regex && Pathname.new(regex).exist?)
         | 
| 300 | 
            +
                    paths.push(regex)
         | 
| 301 | 
            +
                    regex = args.delete_at(-1)
         | 
| 237 302 | 
             
                end
         | 
| 238 303 |  | 
| 239 | 
            -
                if ( | 
| 240 | 
            -
                     | 
| 304 | 
            +
                if (options["regex"])
         | 
| 305 | 
            +
                    args.push(regex) if (regex)
         | 
| 241 306 | 
             
                else
         | 
| 242 | 
            -
                     | 
| 307 | 
            +
                    regex ||= paths.delete_at(-1)
         | 
| 308 | 
            +
                    options["regex"] = regex
         | 
| 243 309 | 
             
                end
         | 
| 244 310 |  | 
| 245 | 
            -
                 | 
| 246 | 
            -
             | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 249 | 
            -
                end
         | 
| 250 | 
            -
                options["pass_args"] = args.join(" ")
         | 
| 311 | 
            +
                options["paths"] = "."
         | 
| 312 | 
            +
                options["paths"] = paths.reverse.join(" ") if (!paths.empty?)
         | 
| 313 | 
            +
             | 
| 314 | 
            +
                options["passthru"] = "#{passthru.join(" ")} #{args.join(" ")}"
         | 
| 251 315 |  | 
| 252 316 | 
             
                return options
         | 
| 253 317 | 
             
            end
         | 
| @@ -259,6 +323,7 @@ begin | |
| 259 323 | 
             
                    FileUtils.rm_f(Pathname.new("~/.zoomrc").expand_path)
         | 
| 260 324 | 
             
                end
         | 
| 261 325 |  | 
| 326 | 
            +
                Zoom::ProfileManager.force_tool(options["tool"])
         | 
| 262 327 | 
             
                zoom = Zoom.new(options["cache_file"])
         | 
| 263 328 | 
             
                Zoom.hilight(!Hilighter.disable?)
         | 
| 264 329 |  | 
| @@ -291,8 +356,7 @@ begin | |
| 291 356 | 
             
                        a.downcase <=> b.downcase
         | 
| 292 357 | 
             
                    end.each do |name|
         | 
| 293 358 | 
             
                        if (name == zoom.config.current_profile_name)
         | 
| 294 | 
            -
                            print "*".red | 
| 295 | 
            -
                            print "*" if (!Zoom.hilight?)
         | 
| 359 | 
            +
                            print "*".red
         | 
| 296 360 | 
             
                        end
         | 
| 297 361 |  | 
| 298 362 | 
             
                        lines = profiles[name].to_s.scan(
         | 
| @@ -314,17 +378,10 @@ begin | |
| 314 378 | 
             
                    zoom.cache.clear
         | 
| 315 379 | 
             
                when "secprofs"
         | 
| 316 380 | 
             
                    zoom.config.add_security_profiles
         | 
| 317 | 
            -
                when "version"
         | 
| 318 | 
            -
                    __FILE__.match(/ruby-zoom-(\d+\.\d+\.\d+)/) do |m|
         | 
| 319 | 
            -
                        puts m[1]
         | 
| 320 | 
            -
                    end
         | 
| 321 381 | 
             
                when "which"
         | 
| 322 382 | 
             
                    name = zoom.config.current_profile_name
         | 
| 323 383 | 
             
                    profile = zoom.config.get_profiles[name]
         | 
| 324 384 |  | 
| 325 | 
            -
                    print "*".red if (Zoom.hilight?)
         | 
| 326 | 
            -
                    print "*" if (!Zoom.hilight?)
         | 
| 327 | 
            -
             | 
| 328 385 | 
             
                    lines = profile.to_s.scan(/\S.{0,76}\S(?=\s|$)|\S+/)
         | 
| 329 386 | 
             
                    puts lines.delete_at(0)
         | 
| 330 387 | 
             
                    lines.each do |line|
         | 
| @@ -333,10 +390,11 @@ begin | |
| 333 390 | 
             
                else
         | 
| 334 391 | 
             
                    # Search and cache results
         | 
| 335 392 | 
             
                    header = Hash.new
         | 
| 336 | 
            -
                    header["args"] = options[" | 
| 393 | 
            +
                    header["args"] = options["passthru"]
         | 
| 394 | 
            +
                    header["debug"] = options["debug"]
         | 
| 337 395 | 
             
                    header["paths"] = options["paths"]
         | 
| 338 | 
            -
                    header["pattern"] = options["pattern"]
         | 
| 339 396 | 
             
                    header["profile_name"] = options["use"]
         | 
| 397 | 
            +
                    header["regex"] = options["regex"]
         | 
| 340 398 | 
             
                    header["translate"] = options["translate_flags"]
         | 
| 341 399 | 
             
                    zoom.run(header)
         | 
| 342 400 | 
             
                end
         | 
    
        data/bin/zc
    CHANGED
    
    | @@ -20,40 +20,70 @@ def parse(args) | |
| 20 20 | 
             
                options = Hash.new
         | 
| 21 21 | 
             
                options["action"] = "exec"
         | 
| 22 22 | 
             
                options["cache_file"] = nil
         | 
| 23 | 
            +
                options["debug"] = false
         | 
| 24 | 
            +
                options["passthru"] = ""
         | 
| 25 | 
            +
                options["tool"] = nil
         | 
| 23 26 | 
             
                options["translate_flags"] = Hash.new
         | 
| 24 27 | 
             
                options["use"] = nil
         | 
| 25 28 | 
             
                options["verbose"] = false
         | 
| 26 29 |  | 
| 27 30 | 
             
                info = [
         | 
| 28 | 
            -
                    "Do you like to search through code using ag, ack, grep,  | 
| 29 | 
            -
                    " | 
| 30 | 
            -
                    "to  | 
| 31 | 
            -
                    "search results in your editor of choice. | 
| 32 | 
            -
                    "large code-bases, it can be a pain to have | 
| 33 | 
            -
                    "find the filename of each result. Zoom prints | 
| 34 | 
            -
                    "in front of each result that  | 
| 35 | 
            -
                    "you can quickly open that tag number with Zoom to jump",
         | 
| 31 | 
            +
                    "Do you like to search through code using ag, ack, grep, pt,",
         | 
| 32 | 
            +
                    "or rg? Good! This tool is for you! Zoom adds some",
         | 
| 33 | 
            +
                    "convenience to grep-like search tools by allowing you to",
         | 
| 34 | 
            +
                    "quickly open your search results in your editor of choice.",
         | 
| 35 | 
            +
                    "When looking at large code-bases, it can be a pain to have",
         | 
| 36 | 
            +
                    "to scroll to find the filename of each result. Zoom prints",
         | 
| 37 | 
            +
                    "a tag number in front of each result that grep outputs.",
         | 
| 38 | 
            +
                    "Then you can quickly open that tag number with Zoom to jump",
         | 
| 36 39 | 
             
                    "straight to the source. Zoom is even persistent across all",
         | 
| 37 40 | 
             
                    "your sessions! You can search in one terminal and jump to a",
         | 
| 38 41 | 
             
                    "tag in another terminal from any directory!"
         | 
| 39 42 | 
             
                ].join(" ")
         | 
| 40 43 |  | 
| 44 | 
            +
                passthru = Array.new
         | 
| 45 | 
            +
             | 
| 41 46 | 
             
                parser = OptionParser.new do |opts|
         | 
| 42 47 | 
             
                    opts.summary_width = 25
         | 
| 43 48 |  | 
| 44 49 | 
             
                    opts.banner = [
         | 
| 45 | 
            -
                        "Usage: #{File.basename($0)} [OPTIONS]",
         | 
| 46 | 
            -
                        "[passthru options] [ | 
| 50 | 
            +
                        "Usage: #{File.basename($0)} [OPTIONS] --",
         | 
| 51 | 
            +
                        "[passthru options] [regex] [path1]...[pathN]"
         | 
| 47 52 | 
             
                    ].join(" ")
         | 
| 48 53 |  | 
| 49 54 | 
             
                    opts.on("", "DESCRIPTION")
         | 
| 50 55 |  | 
| 51 | 
            -
                    info.scan(/\S.{0, | 
| 56 | 
            +
                    info.scan(/\S.{0,66}\S(?=\s|$)|\S+/).each do |line|
         | 
| 52 57 | 
             
                        opts.on("    #{line}")
         | 
| 53 58 | 
             
                    end
         | 
| 54 59 |  | 
| 55 60 | 
             
                    opts.on("", "OPTIONS")
         | 
| 56 61 |  | 
| 62 | 
            +
                    opts.on(
         | 
| 63 | 
            +
                        "-A",
         | 
| 64 | 
            +
                        "--after-context=NUM",
         | 
| 65 | 
            +
                        "Show NUM lines after each match"
         | 
| 66 | 
            +
                    ) do |num|
         | 
| 67 | 
            +
                        passthru.push("-A #{num}")
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    opts.on(
         | 
| 71 | 
            +
                        "-a",
         | 
| 72 | 
            +
                        "--all",
         | 
| 73 | 
            +
                        "Search all files (including binaries and VCS",
         | 
| 74 | 
            +
                        "ignored files)"
         | 
| 75 | 
            +
                    ) do
         | 
| 76 | 
            +
                        options["translate_flags"]["all"] = ""
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                    opts.on(
         | 
| 80 | 
            +
                        "-B",
         | 
| 81 | 
            +
                        "--before-context=NUM",
         | 
| 82 | 
            +
                        "Show NUM lines before each match"
         | 
| 83 | 
            +
                    ) do |num|
         | 
| 84 | 
            +
                        passthru.push("-B #{num}")
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
             | 
| 57 87 | 
             
                    opts.on("-c", "--cache", "Show previous results") do
         | 
| 58 88 | 
             
                        options["action"] = "cache"
         | 
| 59 89 | 
             
                    end
         | 
| @@ -66,10 +96,38 @@ def parse(args) | |
| 66 96 | 
             
                        options["cache_file"] = file
         | 
| 67 97 | 
             
                    end
         | 
| 68 98 |  | 
| 99 | 
            +
                    opts.on(
         | 
| 100 | 
            +
                        "-C",
         | 
| 101 | 
            +
                        "--context=NUM",
         | 
| 102 | 
            +
                        "Show NUM lines before and after each match"
         | 
| 103 | 
            +
                    ) do |num|
         | 
| 104 | 
            +
                        passthru.push("-C #{num}")
         | 
| 105 | 
            +
                    end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                    opts.on(
         | 
| 108 | 
            +
                        "-d",
         | 
| 109 | 
            +
                        "--debug",
         | 
| 110 | 
            +
                        "Show command that would be run (but don't run)"
         | 
| 111 | 
            +
                    ) do
         | 
| 112 | 
            +
                        options["debug"] = true
         | 
| 113 | 
            +
                    end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                    opts.on("-f", "--follow", "Follow symlinks") do
         | 
| 116 | 
            +
                        options["translate_flags"]["follow"] = ""
         | 
| 117 | 
            +
                    end
         | 
| 118 | 
            +
             | 
| 69 119 | 
             
                    opts.on("--find", "Use built-in find profile") do
         | 
| 70 120 | 
             
                        options["use"] = "find"
         | 
| 71 121 | 
             
                    end
         | 
| 72 122 |  | 
| 123 | 
            +
                    opts.on(
         | 
| 124 | 
            +
                        "--force-tool=TOOL",
         | 
| 125 | 
            +
                        "Use the specified tool (with applicable",
         | 
| 126 | 
            +
                        "profiles)"
         | 
| 127 | 
            +
                    ) do |tool|
         | 
| 128 | 
            +
                        options["tool"] = tool
         | 
| 129 | 
            +
                    end
         | 
| 130 | 
            +
             | 
| 73 131 | 
             
                    opts.on(
         | 
| 74 132 | 
             
                        "-g",
         | 
| 75 133 | 
             
                        "--go=NUM",
         | 
| @@ -86,11 +144,11 @@ def parse(args) | |
| 86 144 |  | 
| 87 145 | 
             
                    opts.on(
         | 
| 88 146 | 
             
                        "-i",
         | 
| 89 | 
            -
                        "--ignore= | 
| 90 | 
            -
                        "Ignore files/directories matching  | 
| 91 | 
            -
                    ) do | | 
| 147 | 
            +
                        "--ignore=GLOB",
         | 
| 148 | 
            +
                        "Ignore files/directories matching GLOB"
         | 
| 149 | 
            +
                    ) do |regex|
         | 
| 92 150 | 
             
                        options["translate_flags"]["ignore"] ||= Array.new
         | 
| 93 | 
            -
                        options["translate_flags"]["ignore"].push( | 
| 151 | 
            +
                        options["translate_flags"]["ignore"].push(regex)
         | 
| 94 152 | 
             
                    end
         | 
| 95 153 |  | 
| 96 154 | 
             
                    opts.on("-l", "--list", "List profiles") do
         | 
| @@ -98,11 +156,12 @@ def parse(args) | |
| 98 156 | 
             
                    end
         | 
| 99 157 |  | 
| 100 158 | 
             
                    opts.on(
         | 
| 101 | 
            -
                        "-- | 
| 102 | 
            -
                        "Read  | 
| 159 | 
            +
                        "--regex-file=FILE",
         | 
| 160 | 
            +
                        "Read regexes from lines of file (treated as",
         | 
| 161 | 
            +
                        "OR)"
         | 
| 103 162 | 
             
                    ) do |file|
         | 
| 104 | 
            -
                         | 
| 105 | 
            -
                        options[" | 
| 163 | 
            +
                        regexes = File.open(file).read.split(/[\n\r]+/)
         | 
| 164 | 
            +
                        options["regex"] = "(#{regexes.join(")|(")})"
         | 
| 106 165 | 
             
                    end
         | 
| 107 166 |  | 
| 108 167 | 
             
                    opts.on("-r", "--repeat", "Repeat last Zoom command") do
         | 
| @@ -170,23 +229,29 @@ def parse(args) | |
| 170 229 | 
             
                    end
         | 
| 171 230 |  | 
| 172 231 | 
             
                    opts.on("--version", "Show version") do
         | 
| 173 | 
            -
                         | 
| 232 | 
            +
                        __FILE__.match(/ruby-zoom-(\d+\.\d+\.\d+)/) do |m|
         | 
| 233 | 
            +
                            puts m[1]
         | 
| 234 | 
            +
                        end
         | 
| 235 | 
            +
                        exit ZoomExit::GOOD
         | 
| 174 236 | 
             
                    end
         | 
| 175 237 |  | 
| 176 238 | 
             
                    opts.on(
         | 
| 177 239 | 
             
                        "",
         | 
| 178 240 | 
             
                        "EXAMPLES",
         | 
| 179 241 | 
             
                        "    Execute default profile:",
         | 
| 180 | 
            -
                        "    $ z  | 
| 242 | 
            +
                        "    $ z REGEX",
         | 
| 181 243 | 
             
                        "",
         | 
| 182 244 | 
             
                        "    Execute specified profile:",
         | 
| 183 | 
            -
                        "    $ z -u grep  | 
| 245 | 
            +
                        "    $ z -u grep REGEX",
         | 
| 246 | 
            +
                        "",
         | 
| 247 | 
            +
                        "    Pass additional flags to grep profile:",
         | 
| 248 | 
            +
                        "    $ z -u grep -- --line-regexp REGEX",
         | 
| 184 249 | 
             
                        "",
         | 
| 185 | 
            -
                        "     | 
| 186 | 
            -
                        "    $ z  | 
| 250 | 
            +
                        "    Ignore .class files and test related files",
         | 
| 251 | 
            +
                        "    $ z -i \"*.class\" -i \"*test*\" REGEX",
         | 
| 187 252 | 
             
                        "",
         | 
| 188 | 
            -
                        "    Open tags:",
         | 
| 189 | 
            -
                        "    $  | 
| 253 | 
            +
                        "    Open specified tags:",
         | 
| 254 | 
            +
                        "    $ z --go 10,20,30-40"
         | 
| 190 255 | 
             
                    )
         | 
| 191 256 | 
             
                end
         | 
| 192 257 |  | 
| @@ -230,24 +295,23 @@ def parse(args) | |
| 230 295 | 
             
                end
         | 
| 231 296 |  | 
| 232 297 | 
             
                paths = Array.new
         | 
| 233 | 
            -
                 | 
| 234 | 
            -
                while ( | 
| 235 | 
            -
                    paths.push( | 
| 236 | 
            -
                     | 
| 298 | 
            +
                regex = args.delete_at(-1)
         | 
| 299 | 
            +
                while (regex && Pathname.new(regex).exist?)
         | 
| 300 | 
            +
                    paths.push(regex)
         | 
| 301 | 
            +
                    regex = args.delete_at(-1)
         | 
| 237 302 | 
             
                end
         | 
| 238 303 |  | 
| 239 | 
            -
                if ( | 
| 240 | 
            -
                     | 
| 304 | 
            +
                if (options["regex"])
         | 
| 305 | 
            +
                    args.push(regex) if (regex)
         | 
| 241 306 | 
             
                else
         | 
| 242 | 
            -
                     | 
| 307 | 
            +
                    regex ||= paths.delete_at(-1)
         | 
| 308 | 
            +
                    options["regex"] = regex
         | 
| 243 309 | 
             
                end
         | 
| 244 310 |  | 
| 245 | 
            -
                 | 
| 246 | 
            -
             | 
| 247 | 
            -
             | 
| 248 | 
            -
             | 
| 249 | 
            -
                end
         | 
| 250 | 
            -
                options["pass_args"] = args.join(" ")
         | 
| 311 | 
            +
                options["paths"] = "."
         | 
| 312 | 
            +
                options["paths"] = paths.reverse.join(" ") if (!paths.empty?)
         | 
| 313 | 
            +
             | 
| 314 | 
            +
                options["passthru"] = "#{passthru.join(" ")} #{args.join(" ")}"
         | 
| 251 315 |  | 
| 252 316 | 
             
                return options
         | 
| 253 317 | 
             
            end
         | 
| @@ -259,6 +323,7 @@ begin | |
| 259 323 | 
             
                    FileUtils.rm_f(Pathname.new("~/.zoomrc").expand_path)
         | 
| 260 324 | 
             
                end
         | 
| 261 325 |  | 
| 326 | 
            +
                Zoom::ProfileManager.force_tool(options["tool"])
         | 
| 262 327 | 
             
                zoom = Zoom.new(options["cache_file"])
         | 
| 263 328 | 
             
                Zoom.hilight(!Hilighter.disable?)
         | 
| 264 329 |  | 
| @@ -291,8 +356,7 @@ begin | |
| 291 356 | 
             
                        a.downcase <=> b.downcase
         | 
| 292 357 | 
             
                    end.each do |name|
         | 
| 293 358 | 
             
                        if (name == zoom.config.current_profile_name)
         | 
| 294 | 
            -
                            print "*".red | 
| 295 | 
            -
                            print "*" if (!Zoom.hilight?)
         | 
| 359 | 
            +
                            print "*".red
         | 
| 296 360 | 
             
                        end
         | 
| 297 361 |  | 
| 298 362 | 
             
                        lines = profiles[name].to_s.scan(
         | 
| @@ -314,17 +378,10 @@ begin | |
| 314 378 | 
             
                    zoom.cache.clear
         | 
| 315 379 | 
             
                when "secprofs"
         | 
| 316 380 | 
             
                    zoom.config.add_security_profiles
         | 
| 317 | 
            -
                when "version"
         | 
| 318 | 
            -
                    __FILE__.match(/ruby-zoom-(\d+\.\d+\.\d+)/) do |m|
         | 
| 319 | 
            -
                        puts m[1]
         | 
| 320 | 
            -
                    end
         | 
| 321 381 | 
             
                when "which"
         | 
| 322 382 | 
             
                    name = zoom.config.current_profile_name
         | 
| 323 383 | 
             
                    profile = zoom.config.get_profiles[name]
         | 
| 324 384 |  | 
| 325 | 
            -
                    print "*".red if (Zoom.hilight?)
         | 
| 326 | 
            -
                    print "*" if (!Zoom.hilight?)
         | 
| 327 | 
            -
             | 
| 328 385 | 
             
                    lines = profile.to_s.scan(/\S.{0,76}\S(?=\s|$)|\S+/)
         | 
| 329 386 | 
             
                    puts lines.delete_at(0)
         | 
| 330 387 | 
             
                    lines.each do |line|
         | 
| @@ -333,10 +390,11 @@ begin | |
| 333 390 | 
             
                else
         | 
| 334 391 | 
             
                    # Search and cache results
         | 
| 335 392 | 
             
                    header = Hash.new
         | 
| 336 | 
            -
                    header["args"] = options[" | 
| 393 | 
            +
                    header["args"] = options["passthru"]
         | 
| 394 | 
            +
                    header["debug"] = options["debug"]
         | 
| 337 395 | 
             
                    header["paths"] = options["paths"]
         | 
| 338 | 
            -
                    header["pattern"] = options["pattern"]
         | 
| 339 396 | 
             
                    header["profile_name"] = options["use"]
         | 
| 397 | 
            +
                    header["regex"] = options["regex"]
         | 
| 340 398 | 
             
                    header["translate"] = options["translate_flags"]
         | 
| 341 399 | 
             
                    zoom.run(header)
         | 
| 342 400 | 
             
                end
         |