ruby-zoom 3.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29d3d32183d4228cbd9460f84112c4d52d4c3826
4
+ data.tar.gz: 0348f0d6e07faf1cc11c070be184b6794467f5d1
5
+ SHA512:
6
+ metadata.gz: 0e9b1622e5388fd87459cf7a270d1a37f9a6fca58e47968af606001dabbfb090118971a7a80a94ecae6942c1c3bdb2658e425db47cf131e01807ef820fe01fcf
7
+ data.tar.gz: e944bc6fc229acca5a171b9d2eb6d25355816b1642dcbe7cdd0ac9a9e6b80da02ca01c359be26091cdc4958264813c92de9d9f97c5a5b65bf376199d8976be94
data/bin/z ADDED
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "zoom"
5
+
6
+ class ZoomExit
7
+ GOOD = 0
8
+ INVALID_OPTION = 1
9
+ INVALID_ARGUMENT = 2
10
+ MISSING_ARGUMENT = 3
11
+ EXCEPTION = 4
12
+ end
13
+
14
+ def parse(args)
15
+ options = Hash.new
16
+ options["action"] = "exec"
17
+ options["use"] = nil
18
+
19
+ info = "Do you like to search through code using ag, ack, or " \
20
+ "grep? Good! This tool is for you! Zoom adds some " \
21
+ "convenience to ag/ack/grep by allowing you to quickly " \
22
+ "open your search results in your editor of choice. When " \
23
+ "looking at large code-bases, it can be a pain to have to " \
24
+ "scroll to find the filename of each result. Zoom prints a " \
25
+ "tag number in front of each result that ag/ack/grep " \
26
+ "outputs. Then you can quickly open that tag number with " \
27
+ "Zoom to jump straight to the source. Zoom is even " \
28
+ "persistent across all your sessions! You can search in " \
29
+ "one terminal and jump to a tag in another terminal from " \
30
+ "any directory!"
31
+
32
+ parser = OptionParser.new do |opts|
33
+ opts.banner =
34
+ "Usage: #{File.basename($0)} [OPTIONS] <pattern>"
35
+
36
+ opts.on(
37
+ "-a",
38
+ "--add=NAME",
39
+ "Add a new profile with specified name"
40
+ ) do |name|
41
+ options["action"] = "add"
42
+ options["use"] = name
43
+ end
44
+
45
+ opts.on("-c", "--cache", "Show previous results") do
46
+ options["action"] = "cache"
47
+ end
48
+
49
+ opts.on(
50
+ "-d",
51
+ "--delete=NAME",
52
+ "Delete profile with specified name"
53
+ ) do |name|
54
+ options["action"] = "delete"
55
+ options["use"] = name
56
+ end
57
+
58
+ opts.on(
59
+ "-e",
60
+ "--edit=NAME",
61
+ "Edit profile with specified name"
62
+ ) do |name|
63
+ options["action"] = "edit"
64
+ options["use"] = name
65
+ end
66
+
67
+ opts.on(
68
+ "--editor=EDITOR",
69
+ "Use the specified editor"
70
+ ) do |editor|
71
+ options["action"] = "editor"
72
+ options["use"] = editor
73
+ end
74
+
75
+ opts.on("--examples", "Show some examples") do
76
+ options["action"] = "examples"
77
+ end
78
+
79
+ opts.on("--find", "Use the zoom_find profile") do
80
+ options["use"] = "zoom_find"
81
+ end
82
+
83
+ opts.on(
84
+ "-g",
85
+ "--go=NUM",
86
+ "Open editor to search result NUM"
87
+ ) do |go|
88
+ options["action"] = "go"
89
+ options["use"] = go
90
+ end
91
+
92
+ opts.on("-h", "--help", "Display this help message") do
93
+ puts opts
94
+ exit ZoomExit::GOOD
95
+ end
96
+
97
+ opts.on("-l", "--list", "List profiles") do
98
+ options["action"] = "list_profiles"
99
+ end
100
+
101
+ opts.on(
102
+ "--list-profile-names",
103
+ "List profile names for completion functions"
104
+ ) do
105
+ options["action"] = "list_profile_names"
106
+ end
107
+
108
+ opts.on(
109
+ "--list-tags",
110
+ "List tags for completion functions"
111
+ ) do
112
+ options["action"] = "list_tags"
113
+ end
114
+
115
+ opts.on(
116
+ "--pager",
117
+ "Treat Zoom as a pager (internal use only)"
118
+ ) do
119
+ options["action"] = "pager"
120
+ end
121
+
122
+ opts.on("-r", "--repeat", "Repeat the last Zoom command") do
123
+ options["action"] = "repeat"
124
+ end
125
+
126
+ opts.on("--rc", "Create default .zoomrc file") do
127
+ options["action"] = "rc"
128
+ end
129
+
130
+ opts.on(
131
+ "--rename=NAME",
132
+ "Rename the current profile"
133
+ ) do |name|
134
+ options["action"] = "rename"
135
+ options["rename"] = name
136
+ end
137
+
138
+ opts.on(
139
+ "-s",
140
+ "--switch=NAME",
141
+ "Switch to profile with specified name"
142
+ ) do |name|
143
+ options["action"] = "switch"
144
+ options["use"] = name
145
+ end
146
+
147
+ opts.on(
148
+ "-u",
149
+ "--use=NAME",
150
+ "Use specified profile one time only"
151
+ ) do |name|
152
+ options["use"] = name
153
+ end
154
+
155
+ opts.on("-w", "--which", "Display the current profile") do
156
+ options["action"] = "which"
157
+ end
158
+
159
+ opts.on("", info.word_wrap(80))
160
+ end
161
+
162
+ begin
163
+ parser.parse!
164
+ rescue OptionParser::InvalidOption => e
165
+ puts e.message
166
+ puts parser
167
+ exit ZoomExit::INVALID_OPTION
168
+ rescue OptionParser::InvalidArgument => e
169
+ puts e.message
170
+ puts parser
171
+ exit ZoomExit::INVALID_ARGUMENT
172
+ rescue OptionParser::MissingArgument => e
173
+ puts e.message
174
+ puts parser
175
+ exit ZoomExit::MISSING_ARGUMENT
176
+ end
177
+
178
+ case File.basename($0)
179
+ when "zc"
180
+ options["action"] = "cache"
181
+ when "zf"
182
+ options["use"] = "zoom_find"
183
+ when "zg"
184
+ options["action"] = "go"
185
+ options["use"] = args[0]
186
+ when "zl"
187
+ options["action"] = "list_profiles"
188
+ when "zr"
189
+ options["action"] = "repeat"
190
+ when "z"
191
+ # do nothing, this is the normal usage
192
+ else
193
+ options["use"] = File.basename($0)
194
+ end
195
+
196
+ options["pattern"] = args.delete_at(-1)
197
+ options["subargs"] = args.join(" ")
198
+ return options
199
+ end
200
+
201
+ options = parse(ARGV)
202
+
203
+ begin
204
+ case options["action"]
205
+ when "add"
206
+ Zoom.instance.interactive_add_profile(options["use"])
207
+ when "cache"
208
+ Zoom.instance.shortcut_cache
209
+ when "delete"
210
+ Zoom.instance.delete_profile(options["use"])
211
+ when "edit"
212
+ Zoom.instance.interactive_edit_profile(options["use"])
213
+ when "editor"
214
+ Zoom.instance.configure_editor(options["use"])
215
+ when "examples"
216
+ puts [
217
+ "EXAMPLES:",
218
+ "",
219
+ "Add a profile named test:",
220
+ " $ z --add test",
221
+ "",
222
+ "Edit a profile named test:",
223
+ " $ z --edit test",
224
+ "",
225
+ "Execute the current profile:",
226
+ " $ z PATTERN",
227
+ "",
228
+ "Repeat the previous Zoom command:",
229
+ " $ z --repeat",
230
+ "",
231
+ "Pass additional flags to the choosen operator:",
232
+ " $ z -- -A 3 PATTERN",
233
+ "",
234
+ "Open a tag:",
235
+ " $ z --go 10",
236
+ "",
237
+ "Open multiple tags:",
238
+ " $ z --go 10,20,30-40"
239
+ ].join("\n")
240
+ when "go"
241
+ Zoom.instance.loop_through_results(options["use"])
242
+ when "list_profiles"
243
+ Zoom.instance.list_profiles
244
+ when "list_profile_names"
245
+ Zoom.instance.list_profile_names
246
+ when "list_tags"
247
+ Zoom.instance.list_tags
248
+ when "pager"
249
+ Zoom.instance.pager
250
+ when "repeat"
251
+ Zoom.instance.repeat
252
+ when "rc"
253
+ Zoom.instance.default
254
+ when "rename"
255
+ Zoom.instance.rename_profile(
256
+ options["rename"],
257
+ options["use"]
258
+ )
259
+ when "switch"
260
+ Zoom.instance.switch_profile(options["use"])
261
+ when "which"
262
+ Zoom.instance.show_current
263
+ else
264
+ # Search and save results
265
+ Zoom.instance.exec_profile(
266
+ options["use"],
267
+ options["subargs"],
268
+ options["pattern"]
269
+ )
270
+ end
271
+ rescue ZoomError::Error => e
272
+ puts e.message
273
+ exit ZoomExit::EXCEPTION
274
+ end
275
+ exit ZoomExit::GOOD
data/bin/zc ADDED
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "zoom"
5
+
6
+ class ZoomExit
7
+ GOOD = 0
8
+ INVALID_OPTION = 1
9
+ INVALID_ARGUMENT = 2
10
+ MISSING_ARGUMENT = 3
11
+ EXCEPTION = 4
12
+ end
13
+
14
+ def parse(args)
15
+ options = Hash.new
16
+ options["action"] = "exec"
17
+ options["use"] = nil
18
+
19
+ info = "Do you like to search through code using ag, ack, or " \
20
+ "grep? Good! This tool is for you! Zoom adds some " \
21
+ "convenience to ag/ack/grep by allowing you to quickly " \
22
+ "open your search results in your editor of choice. When " \
23
+ "looking at large code-bases, it can be a pain to have to " \
24
+ "scroll to find the filename of each result. Zoom prints a " \
25
+ "tag number in front of each result that ag/ack/grep " \
26
+ "outputs. Then you can quickly open that tag number with " \
27
+ "Zoom to jump straight to the source. Zoom is even " \
28
+ "persistent across all your sessions! You can search in " \
29
+ "one terminal and jump to a tag in another terminal from " \
30
+ "any directory!"
31
+
32
+ parser = OptionParser.new do |opts|
33
+ opts.banner =
34
+ "Usage: #{File.basename($0)} [OPTIONS] <pattern>"
35
+
36
+ opts.on(
37
+ "-a",
38
+ "--add=NAME",
39
+ "Add a new profile with specified name"
40
+ ) do |name|
41
+ options["action"] = "add"
42
+ options["use"] = name
43
+ end
44
+
45
+ opts.on("-c", "--cache", "Show previous results") do
46
+ options["action"] = "cache"
47
+ end
48
+
49
+ opts.on(
50
+ "-d",
51
+ "--delete=NAME",
52
+ "Delete profile with specified name"
53
+ ) do |name|
54
+ options["action"] = "delete"
55
+ options["use"] = name
56
+ end
57
+
58
+ opts.on(
59
+ "-e",
60
+ "--edit=NAME",
61
+ "Edit profile with specified name"
62
+ ) do |name|
63
+ options["action"] = "edit"
64
+ options["use"] = name
65
+ end
66
+
67
+ opts.on(
68
+ "--editor=EDITOR",
69
+ "Use the specified editor"
70
+ ) do |editor|
71
+ options["action"] = "editor"
72
+ options["use"] = editor
73
+ end
74
+
75
+ opts.on("--examples", "Show some examples") do
76
+ options["action"] = "examples"
77
+ end
78
+
79
+ opts.on("--find", "Use the zoom_find profile") do
80
+ options["use"] = "zoom_find"
81
+ end
82
+
83
+ opts.on(
84
+ "-g",
85
+ "--go=NUM",
86
+ "Open editor to search result NUM"
87
+ ) do |go|
88
+ options["action"] = "go"
89
+ options["use"] = go
90
+ end
91
+
92
+ opts.on("-h", "--help", "Display this help message") do
93
+ puts opts
94
+ exit ZoomExit::GOOD
95
+ end
96
+
97
+ opts.on("-l", "--list", "List profiles") do
98
+ options["action"] = "list_profiles"
99
+ end
100
+
101
+ opts.on(
102
+ "--list-profile-names",
103
+ "List profile names for completion functions"
104
+ ) do
105
+ options["action"] = "list_profile_names"
106
+ end
107
+
108
+ opts.on(
109
+ "--list-tags",
110
+ "List tags for completion functions"
111
+ ) do
112
+ options["action"] = "list_tags"
113
+ end
114
+
115
+ opts.on(
116
+ "--pager",
117
+ "Treat Zoom as a pager (internal use only)"
118
+ ) do
119
+ options["action"] = "pager"
120
+ end
121
+
122
+ opts.on("-r", "--repeat", "Repeat the last Zoom command") do
123
+ options["action"] = "repeat"
124
+ end
125
+
126
+ opts.on("--rc", "Create default .zoomrc file") do
127
+ options["action"] = "rc"
128
+ end
129
+
130
+ opts.on(
131
+ "--rename=NAME",
132
+ "Rename the current profile"
133
+ ) do |name|
134
+ options["action"] = "rename"
135
+ options["rename"] = name
136
+ end
137
+
138
+ opts.on(
139
+ "-s",
140
+ "--switch=NAME",
141
+ "Switch to profile with specified name"
142
+ ) do |name|
143
+ options["action"] = "switch"
144
+ options["use"] = name
145
+ end
146
+
147
+ opts.on(
148
+ "-u",
149
+ "--use=NAME",
150
+ "Use specified profile one time only"
151
+ ) do |name|
152
+ options["use"] = name
153
+ end
154
+
155
+ opts.on("-w", "--which", "Display the current profile") do
156
+ options["action"] = "which"
157
+ end
158
+
159
+ opts.on("", info.word_wrap(80))
160
+ end
161
+
162
+ begin
163
+ parser.parse!
164
+ rescue OptionParser::InvalidOption => e
165
+ puts e.message
166
+ puts parser
167
+ exit ZoomExit::INVALID_OPTION
168
+ rescue OptionParser::InvalidArgument => e
169
+ puts e.message
170
+ puts parser
171
+ exit ZoomExit::INVALID_ARGUMENT
172
+ rescue OptionParser::MissingArgument => e
173
+ puts e.message
174
+ puts parser
175
+ exit ZoomExit::MISSING_ARGUMENT
176
+ end
177
+
178
+ case File.basename($0)
179
+ when "zc"
180
+ options["action"] = "cache"
181
+ when "zf"
182
+ options["use"] = "zoom_find"
183
+ when "zg"
184
+ options["action"] = "go"
185
+ options["use"] = args[0]
186
+ when "zl"
187
+ options["action"] = "list_profiles"
188
+ when "zr"
189
+ options["action"] = "repeat"
190
+ when "z"
191
+ # do nothing, this is the normal usage
192
+ else
193
+ options["use"] = File.basename($0)
194
+ end
195
+
196
+ options["pattern"] = args.delete_at(-1)
197
+ options["subargs"] = args.join(" ")
198
+ return options
199
+ end
200
+
201
+ options = parse(ARGV)
202
+
203
+ begin
204
+ case options["action"]
205
+ when "add"
206
+ Zoom.instance.interactive_add_profile(options["use"])
207
+ when "cache"
208
+ Zoom.instance.shortcut_cache
209
+ when "delete"
210
+ Zoom.instance.delete_profile(options["use"])
211
+ when "edit"
212
+ Zoom.instance.interactive_edit_profile(options["use"])
213
+ when "editor"
214
+ Zoom.instance.configure_editor(options["use"])
215
+ when "examples"
216
+ puts [
217
+ "EXAMPLES:",
218
+ "",
219
+ "Add a profile named test:",
220
+ " $ z --add test",
221
+ "",
222
+ "Edit a profile named test:",
223
+ " $ z --edit test",
224
+ "",
225
+ "Execute the current profile:",
226
+ " $ z PATTERN",
227
+ "",
228
+ "Repeat the previous Zoom command:",
229
+ " $ z --repeat",
230
+ "",
231
+ "Pass additional flags to the choosen operator:",
232
+ " $ z -- -A 3 PATTERN",
233
+ "",
234
+ "Open a tag:",
235
+ " $ z --go 10",
236
+ "",
237
+ "Open multiple tags:",
238
+ " $ z --go 10,20,30-40"
239
+ ].join("\n")
240
+ when "go"
241
+ Zoom.instance.loop_through_results(options["use"])
242
+ when "list_profiles"
243
+ Zoom.instance.list_profiles
244
+ when "list_profile_names"
245
+ Zoom.instance.list_profile_names
246
+ when "list_tags"
247
+ Zoom.instance.list_tags
248
+ when "pager"
249
+ Zoom.instance.pager
250
+ when "repeat"
251
+ Zoom.instance.repeat
252
+ when "rc"
253
+ Zoom.instance.default
254
+ when "rename"
255
+ Zoom.instance.rename_profile(
256
+ options["rename"],
257
+ options["use"]
258
+ )
259
+ when "switch"
260
+ Zoom.instance.switch_profile(options["use"])
261
+ when "which"
262
+ Zoom.instance.show_current
263
+ else
264
+ # Search and save results
265
+ Zoom.instance.exec_profile(
266
+ options["use"],
267
+ options["subargs"],
268
+ options["pattern"]
269
+ )
270
+ end
271
+ rescue ZoomError::Error => e
272
+ puts e.message
273
+ exit ZoomExit::EXCEPTION
274
+ end
275
+ exit ZoomExit::GOOD