ruby-zoom 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/z +275 -0
- data/bin/zc +275 -0
- data/bin/zf +275 -0
- data/bin/zg +275 -0
- data/bin/zl +275 -0
- data/bin/zr +275 -0
- data/lib/ack_profile.rb +48 -0
- data/lib/ag_profile.rb +41 -0
- data/lib/find_profile.rb +28 -0
- data/lib/grep_profile.rb +48 -0
- data/lib/passwords_profile.rb +67 -0
- data/lib/string.rb +26 -0
- data/lib/zoom.rb +621 -0
- data/lib/zoom_error.rb +34 -0
- data/lib/zoom_profile.rb +91 -0
- metadata +112 -0
data/bin/zf
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/zg
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
|