ruby-zoom 4.7.5 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/zf 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, or",
29
- "pt? Good! This tool is for you! Zoom adds some convenience",
30
- "to ag/ack/grep/pt by allowing you to quickly open your",
31
- "search results in your editor of choice. When looking at",
32
- "large code-bases, it can be a pain to have to scroll to",
33
- "find the filename of each result. Zoom prints a tag number",
34
- "in front of each result that ag/ack/grep/pt outputs. Then",
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] [pattern] [path1]...[pathN]"
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,76}\S(?=\s|$)|\S+/).each do |line|
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=PATTERN",
90
- "Ignore files/directories matching PATTERN"
91
- ) do |pattern|
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(pattern)
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
- "--pattern-file=FILE",
102
- "Read patterns from file. One per line. Treated as OR."
159
+ "--regex-file=FILE",
160
+ "Read regexes from lines of file (treated as",
161
+ "OR)"
103
162
  ) do |file|
104
- patterns = File.open(file).read.split(/[\n\r]+/)
105
- options["pattern"] = "(#{patterns.join(")|(")})"
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
- options["action"] = "version"
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 PATTERN",
242
+ " $ z REGEX",
181
243
  "",
182
244
  " Execute specified profile:",
183
- " $ z -u grep PATTERN",
245
+ " $ z -u grep REGEX",
246
+ "",
247
+ " Pass additional flags to grep profile:",
248
+ " $ z -u grep -- --line-regexp REGEX",
184
249
  "",
185
- " Pass additional flags to default profile:",
186
- " $ z -- -A 3 PATTERN",
250
+ " Ignore .class files and test related files",
251
+ " $ z -i \"*.class\" -i \"*test*\" REGEX",
187
252
  "",
188
- " Open tags:",
189
- " $ zg 10,20,30-40"
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
- pattern = args.delete_at(-1)
234
- while (pattern && Pathname.new(pattern).exist?)
235
- paths.push(pattern)
236
- pattern = args.delete_at(-1)
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 (!paths.empty?)
240
- options["paths"] = paths.reverse.join(" ")
304
+ if (options["regex"])
305
+ args.push(regex) if (regex)
241
306
  else
242
- options["paths"] = "."
307
+ regex ||= paths.delete_at(-1)
308
+ options["regex"] = regex
243
309
  end
244
310
 
245
- if (options["pattern"])
246
- args.push(pattern)
247
- else
248
- options["pattern"] = pattern
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 if (Zoom.hilight?)
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["pass_args"]
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/zg 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, or",
29
- "pt? Good! This tool is for you! Zoom adds some convenience",
30
- "to ag/ack/grep/pt by allowing you to quickly open your",
31
- "search results in your editor of choice. When looking at",
32
- "large code-bases, it can be a pain to have to scroll to",
33
- "find the filename of each result. Zoom prints a tag number",
34
- "in front of each result that ag/ack/grep/pt outputs. Then",
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] [pattern] [path1]...[pathN]"
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,76}\S(?=\s|$)|\S+/).each do |line|
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=PATTERN",
90
- "Ignore files/directories matching PATTERN"
91
- ) do |pattern|
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(pattern)
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
- "--pattern-file=FILE",
102
- "Read patterns from file. One per line. Treated as OR."
159
+ "--regex-file=FILE",
160
+ "Read regexes from lines of file (treated as",
161
+ "OR)"
103
162
  ) do |file|
104
- patterns = File.open(file).read.split(/[\n\r]+/)
105
- options["pattern"] = "(#{patterns.join(")|(")})"
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
- options["action"] = "version"
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 PATTERN",
242
+ " $ z REGEX",
181
243
  "",
182
244
  " Execute specified profile:",
183
- " $ z -u grep PATTERN",
245
+ " $ z -u grep REGEX",
246
+ "",
247
+ " Pass additional flags to grep profile:",
248
+ " $ z -u grep -- --line-regexp REGEX",
184
249
  "",
185
- " Pass additional flags to default profile:",
186
- " $ z -- -A 3 PATTERN",
250
+ " Ignore .class files and test related files",
251
+ " $ z -i \"*.class\" -i \"*test*\" REGEX",
187
252
  "",
188
- " Open tags:",
189
- " $ zg 10,20,30-40"
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
- pattern = args.delete_at(-1)
234
- while (pattern && Pathname.new(pattern).exist?)
235
- paths.push(pattern)
236
- pattern = args.delete_at(-1)
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 (!paths.empty?)
240
- options["paths"] = paths.reverse.join(" ")
304
+ if (options["regex"])
305
+ args.push(regex) if (regex)
241
306
  else
242
- options["paths"] = "."
307
+ regex ||= paths.delete_at(-1)
308
+ options["regex"] = regex
243
309
  end
244
310
 
245
- if (options["pattern"])
246
- args.push(pattern)
247
- else
248
- options["pattern"] = pattern
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 if (Zoom.hilight?)
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["pass_args"]
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