hookapp 2.0.5 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +26 -3
- data/Rakefile +7 -3
- data/bin/hook +49 -2
- data/buildnotes.md +30 -0
- data/hook.rdoc +21 -2
- data/lib/helpers/fuzzyfilefinder +0 -0
- data/lib/hook/hookapp.rb +29 -10
- data/lib/hook/string.rb +4 -0
- data/lib/hook/version.rb +1 -1
- data/test/helpers/hook-helpers.rb +76 -0
- data/test/hook_clip_test.rb +24 -0
- data/test/hook_clone_test.rb +30 -0
- data/test/hook_encode_test.rb +30 -0
- data/test/hook_link_test.rb +39 -0
- data/test/hook_list_test.rb +25 -0
- data/test/hook_remove_test.rb +34 -0
- data/test/hook_scripts_test.rb +21 -0
- metadata +10 -69
- data/html/App.html +0 -107
- data/html/GLI/Commands/Doc.html +0 -91
- data/html/GLI/Commands/MarkdownDocumentListener.html +0 -511
- data/html/GLI/Commands.html +0 -91
- data/html/GLI.html +0 -91
- data/html/Hook.html +0 -100
- data/html/HookApp.html +0 -946
- data/html/Hooker.html +0 -141
- data/html/README_rdoc.html +0 -325
- data/html/String.html +0 -313
- data/html/created.rid +0 -9
- data/html/css/fonts.css +0 -167
- data/html/css/rdoc.css +0 -639
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +0 -293
- data/html/js/darkfish.js +0 -84
- data/html/js/navigation.js +0 -105
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +0 -110
- data/html/js/search_index.js +0 -1
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +0 -229
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +0 -345
- data/test/default_test.rb +0 -14
- data/test/hookfiles/01.test +0 -0
- data/test/hookfiles/02.test +0 -0
- data/test/hookfiles/03.test +0 -0
- data/test/hookfiles/04.test +0 -0
- data/test/hookfiles/05.test +0 -0
- data/test/hookfiles/06.test +0 -0
- data/test/hookfiles/07.test +0 -0
- data/test/hookfiles/08.test +0 -0
- data/test/hookfiles/09.test +0 -0
- data/test/hookfiles/10.test +0 -0
- data/test/hookfiles/11.test +0 -0
- data/test/hookfiles/12.test +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 477033a68381137c2a2c67a486896da5d1210fb8d261950beff09df64b0b6566
|
4
|
+
data.tar.gz: b3de73462923bc91c88c7ab58b3c8fc7195ffe19cb4d09bef2acd3d0e579e7d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c64691a5a0ddc289590408efd13936e352962838f182ec905dfd8ac706197e6f5538d2cbe2a108b1a72f7ace459d90d36d1b789cf48bc7a6871391c871698a24
|
7
|
+
data.tar.gz: 3b91f789621f9cf091793ac75d9d44b61c09c2c07ae34fc4e84495ee670c2016c8583b71d00c067917f12aff77e603b389773a1cf4acb8a3a12bcd9cea2ac1bb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
CLI interface for Hook.app (macOS)
|
4
4
|
|
5
|
-
> Hook.app is a productivity tool for macOS <https://hookproductivity.com/>.
|
5
|
+
> Hook.app is a productivity tool for macOS <https://hookproductivity.com/>.
|
6
|
+
This gem includes a `hook` binary that allows interaction with the features of Hook.app.
|
6
7
|
|
7
|
-
*v2.0.
|
8
|
+
*v2.0.7*
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
@@ -257,6 +258,24 @@ Generate a menu to select hook(s) for opening
|
|
257
258
|
|
258
259
|
* * * * * *
|
259
260
|
|
261
|
+
### `$ hook` <mark>`percent`</mark> ` STRING`
|
262
|
+
|
263
|
+
*Percent encode/decode a string*
|
264
|
+
|
265
|
+
> Use encode or decode to apply Hook's url encoding to a string argument. Use '-' to read input from STDIN.
|
266
|
+
|
267
|
+
#### Commands
|
268
|
+
|
269
|
+
##### `$ hook` <mark>`decode`</mark> ` STRING`
|
270
|
+
|
271
|
+
*decode a percent-encoded string*
|
272
|
+
|
273
|
+
##### `$ hook` <mark>`encode`</mark> ` STRING`
|
274
|
+
|
275
|
+
*percent encode a string*
|
276
|
+
|
277
|
+
* * * * * *
|
278
|
+
|
260
279
|
### `$ hook` <mark>`remove|rm`</mark> ` ITEM_1 ITEM_2`
|
261
280
|
|
262
281
|
*Remove a hook between two files/urls*
|
@@ -271,6 +290,10 @@ Generate a menu to select hook(s) for opening
|
|
271
290
|
|
272
291
|
Remove ALL links on files, requires confirmation
|
273
292
|
|
293
|
+
##### `-f`|`--force`
|
294
|
+
|
295
|
+
|
296
|
+
|
274
297
|
* * * * * *
|
275
298
|
|
276
299
|
### `$ hook` <mark>`scripts`</mark> ` SHELL`
|
@@ -325,5 +348,5 @@ This software is licensed under the MIT License.
|
|
325
348
|
THE SOFTWARE.
|
326
349
|
|
327
350
|
|
328
|
-
Documentation generated 2021-09-
|
351
|
+
Documentation generated 2021-09-25 07:37
|
329
352
|
|
data/Rakefile
CHANGED
@@ -4,6 +4,7 @@ require 'rubygems/package_task'
|
|
4
4
|
require 'rdoc/task'
|
5
5
|
require 'cucumber'
|
6
6
|
require 'cucumber/rake/task'
|
7
|
+
require 'rake/testtask'
|
7
8
|
Rake::RDocTask.new do |rd|
|
8
9
|
rd.main = "README.rdoc"
|
9
10
|
rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
|
@@ -14,6 +15,7 @@ spec = eval(File.read('hookapp.gemspec'))
|
|
14
15
|
|
15
16
|
Gem::PackageTask.new(spec) do |pkg|
|
16
17
|
end
|
18
|
+
|
17
19
|
CUKE_RESULTS = 'results.html'
|
18
20
|
CLEAN << CUKE_RESULTS
|
19
21
|
desc 'Run features'
|
@@ -35,10 +37,12 @@ end
|
|
35
37
|
task :cucumber => :features
|
36
38
|
task 'cucumber:wip' => 'features:wip'
|
37
39
|
task :wip => 'features:wip'
|
38
|
-
|
40
|
+
|
39
41
|
Rake::TestTask.new do |t|
|
40
|
-
t.libs <<
|
42
|
+
t.libs << ['test', 'test/helpers']
|
41
43
|
t.test_files = FileList['test/*_test.rb']
|
44
|
+
t.verbose = ENV['VERBOSE'] =~ /(true|1)/i ? true : false
|
42
45
|
end
|
43
46
|
|
44
|
-
task :default => [:test,:features]
|
47
|
+
# task :default => [:test,:features]
|
48
|
+
task :default => [:test]
|
data/bin/hook
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'hook'
|
5
|
+
require 'shellwords'
|
5
6
|
|
6
7
|
# Main class for GLI app
|
7
8
|
class App
|
8
9
|
extend GLI::App
|
9
10
|
|
10
11
|
program_desc 'CLI interface for Hook.app (macOS)'
|
11
|
-
program_long_desc 'Hook.app is a productivity tool for macOS <https://hookproductivity.com/>.
|
12
|
+
program_long_desc 'Hook.app is a productivity tool for macOS <https://hookproductivity.com/>.
|
13
|
+
This gem includes a `hook` binary that allows interaction with the features of Hook.app.'
|
12
14
|
default_command 'help'
|
13
15
|
autocomplete_commands = true
|
14
16
|
synopsis_format(:terminal)
|
@@ -19,6 +21,7 @@ class App
|
|
19
21
|
arguments :strict
|
20
22
|
|
21
23
|
hookapp = nil
|
24
|
+
stdin = nil
|
22
25
|
|
23
26
|
desc 'List hooks on a file or url'
|
24
27
|
long_desc %{
|
@@ -215,9 +218,10 @@ If --all isn't specified, exactly two arguments (Files/URLs) are required.
|
|
215
218
|
command %i[remove rm] do |c|
|
216
219
|
c.desc 'Remove ALL links on files, requires confirmation'
|
217
220
|
c.switch %i[a all], { negatable: false, default_value: false }
|
221
|
+
c.switch %i[f force], { negatable: false, default_value: false }
|
218
222
|
|
219
223
|
c.action do |_global_options, options, args|
|
220
|
-
result = hookapp.delete_hooks(args, { all: options[:
|
224
|
+
result = hookapp.delete_hooks(args, { all: options[:all], force: options[:force] })
|
221
225
|
puts result
|
222
226
|
end
|
223
227
|
end
|
@@ -264,12 +268,55 @@ Opens Hook.app on the specified file/URL for browsing and performing actions. Ex
|
|
264
268
|
end
|
265
269
|
end
|
266
270
|
|
271
|
+
desc 'Percent encode/decode a string'
|
272
|
+
long_desc %{Use encode or decode to apply Hook's url encoding to a string argument. Use '-' to read input from STDIN.}
|
273
|
+
arg_name 'STRING'
|
274
|
+
command :percent do |c|
|
275
|
+
c.desc 'percent encode a string'
|
276
|
+
c.arg_name 'STRING'
|
277
|
+
c.command :encode do |enc|
|
278
|
+
enc.action do |_global_options, _options, args|
|
279
|
+
if stdin
|
280
|
+
string = stdin
|
281
|
+
else
|
282
|
+
exit_now!('no string provided') unless args.size.positive?
|
283
|
+
|
284
|
+
string = args.join(' ').strip
|
285
|
+
end
|
286
|
+
|
287
|
+
print hookapp.encode(string)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
c.desc 'decode a percent-encoded string'
|
292
|
+
c.arg_name 'STRING'
|
293
|
+
c.command :decode do |dec|
|
294
|
+
dec.action do |_global_options, _options, args|
|
295
|
+
if stdin
|
296
|
+
string = stdin
|
297
|
+
else
|
298
|
+
exit_now! ('no string provided') unless args.size.positive?
|
299
|
+
|
300
|
+
string = args.join(' ').strip
|
301
|
+
end
|
302
|
+
|
303
|
+
print hookapp.decode(string)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# c.default_command :encode
|
308
|
+
end
|
309
|
+
|
267
310
|
pre do |global, _command, _options, _args|
|
268
311
|
# Pre logic here
|
269
312
|
# Return true to proceed; false to abort and not call the
|
270
313
|
# chosen command
|
271
314
|
# Use skips_pre before a command to skip this block
|
272
315
|
# on that command only
|
316
|
+
if !STDIN.tty?
|
317
|
+
stdin = STDIN.read.strip
|
318
|
+
end
|
319
|
+
|
273
320
|
hookapp = HookApp.new
|
274
321
|
true
|
275
322
|
end
|
data/buildnotes.md
CHANGED
@@ -27,3 +27,33 @@ Helpers and main classes are in `lib/`.
|
|
27
27
|
Update the docs with `bundle exec bin/hook _doc --format=markdown` and `bundle exec bin/hook _doc --format=rdoc`, then run `rake rerdoc`
|
28
28
|
|
29
29
|
@run(bundle exec bin/hook _doc --format=rdoc && bundle exec bin/hook _doc --format=markdown && rake rerdoc)
|
30
|
+
|
31
|
+
## Test
|
32
|
+
|
33
|
+
Run all tests using `rake test`.
|
34
|
+
|
35
|
+
Run verbose using `rake test TESTOPT="-v"`
|
36
|
+
|
37
|
+
Run a single test using `rake test TEST=test/TEST_FILE.rb`
|
38
|
+
|
39
|
+
This howzit task accepts an optional argument pointing to a specific test (just the test part of the filename, e.g. archive runs `test/doing_archive_test.rb`).
|
40
|
+
|
41
|
+
`howzit -r test -- archive` (or `bld test archive` with the Fish function)
|
42
|
+
|
43
|
+
```run
|
44
|
+
#!/bin/bash
|
45
|
+
if [[ -n $1 ]]; then
|
46
|
+
rake test TESTOPT="-v" TEST=test/hook_$1_test.rb
|
47
|
+
if [[ $? != 0 ]]; then
|
48
|
+
echo "Available tests"
|
49
|
+
echo -e "\033[1;32;40m"
|
50
|
+
FILES="test/hook_*_test.rb"
|
51
|
+
for file in $FILES; do
|
52
|
+
echo $(basename $file ".rb") | sed -E 's/hook_(.*)_test/- \1/'
|
53
|
+
done
|
54
|
+
echo -e "\033[0m"
|
55
|
+
fi
|
56
|
+
else
|
57
|
+
rake test TESTOPT="-v"
|
58
|
+
fi
|
59
|
+
```
|
data/hook.rdoc
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
== hook - CLI interface for Hook.app (macOS)
|
2
2
|
|
3
|
-
Hook.app is a productivity tool for macOS <https://hookproductivity.com/>.
|
3
|
+
Hook.app is a productivity tool for macOS <https://hookproductivity.com/>.
|
4
|
+
This gem includes a `hook` binary that allows interaction with the features of Hook.app.
|
4
5
|
|
5
|
-
v2.0.
|
6
|
+
v2.0.7
|
6
7
|
|
7
8
|
=== Global Options
|
8
9
|
=== --help
|
@@ -151,6 +152,19 @@ This option is a shortcut to `hook select` and overrides any other arguments.
|
|
151
152
|
Open the specified file or url in Hook GUI
|
152
153
|
|
153
154
|
Opens Hook.app on the specified file/URL for browsing and performing actions. Exactly one argument (File/URL) required.
|
155
|
+
==== Command: <tt>percent STRING</tt>
|
156
|
+
Percent encode/decode a string
|
157
|
+
|
158
|
+
Use encode or decode to apply Hook's url encoding to a string argument. Use '-' to read input from STDIN.
|
159
|
+
===== Commands
|
160
|
+
====== Command: <tt>decode STRING</tt>
|
161
|
+
decode a percent-encoded string
|
162
|
+
|
163
|
+
|
164
|
+
====== Command: <tt>encode STRING</tt>
|
165
|
+
percent encode a string
|
166
|
+
|
167
|
+
|
154
168
|
==== Command: <tt>remove|rm ITEM_1 ITEM_2</tt>
|
155
169
|
Remove a hook between two files/urls
|
156
170
|
|
@@ -163,6 +177,11 @@ Remove ALL links on files, requires confirmation
|
|
163
177
|
|
164
178
|
|
165
179
|
|
180
|
+
===== -f|--force
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
166
185
|
==== Command: <tt>scripts SHELL</tt>
|
167
186
|
Shell completion examples
|
168
187
|
|
data/lib/helpers/fuzzyfilefinder
CHANGED
Binary file
|
data/lib/hook/hookapp.rb
CHANGED
@@ -171,9 +171,9 @@ class HookApp
|
|
171
171
|
output = output_array(result, opts)
|
172
172
|
|
173
173
|
if opts[:format] =~ /^v/
|
174
|
-
"Search results for: #{search}\n---------\n" + output.join("\n")
|
174
|
+
"Search results for: #{search}\n---------\n" + output.join("\n") if output
|
175
175
|
else
|
176
|
-
output.join(separator)
|
176
|
+
output.join(separator) if output
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
@@ -334,10 +334,13 @@ class HookApp
|
|
334
334
|
end
|
335
335
|
|
336
336
|
# Delete all hooked files/urls from target file
|
337
|
-
def delete_all_hooks(url)
|
338
|
-
|
339
|
-
|
340
|
-
|
337
|
+
def delete_all_hooks(url, force: false)
|
338
|
+
unless force
|
339
|
+
STDERR.print "Are you sure you want to delete ALL hooks from #{url} (y/N)? "
|
340
|
+
res = STDIN.gets.strip
|
341
|
+
end
|
342
|
+
|
343
|
+
if res =~ /^y/i || force
|
341
344
|
get_hooks(url).each do |hook|
|
342
345
|
`osascript <<'APPLESCRIPT'
|
343
346
|
tell application "Hook"
|
@@ -360,7 +363,7 @@ class HookApp
|
|
360
363
|
urls.each_with_index do |url, i|
|
361
364
|
raise "Invalid target: #{args[i]}" unless url
|
362
365
|
|
363
|
-
output.push(delete_all_hooks(url))
|
366
|
+
output.push(delete_all_hooks(url, force: opts[:force]))
|
364
367
|
end
|
365
368
|
return output.join("\n")
|
366
369
|
end
|
@@ -431,7 +434,7 @@ class HookApp
|
|
431
434
|
hooks_arr = get_hooks(url)
|
432
435
|
|
433
436
|
output = output_array(hooks_arr, opts)
|
434
|
-
result.push({ file: filename, links: output.join(separator) })
|
437
|
+
result.push({ file: filename, links: output.join(separator) }) if output
|
435
438
|
end
|
436
439
|
|
437
440
|
|
@@ -479,11 +482,27 @@ class HookApp
|
|
479
482
|
end
|
480
483
|
end
|
481
484
|
else
|
482
|
-
|
485
|
+
warn 'No bookmarks'
|
483
486
|
end
|
484
487
|
|
485
488
|
output
|
486
489
|
end
|
487
|
-
end
|
488
490
|
|
491
|
+
def encode(string)
|
492
|
+
result = `osascript <<'APPLESCRIPT'
|
493
|
+
tell application "Hook"
|
494
|
+
percent encode "#{string.escape_quotes}"
|
495
|
+
end tell
|
496
|
+
APPLESCRIPT`.strip.gsub(/'/,'%27')
|
497
|
+
print result
|
498
|
+
end
|
489
499
|
|
500
|
+
def decode(string)
|
501
|
+
result = `osascript <<'APPLESCRIPT'
|
502
|
+
tell application "Hook"
|
503
|
+
percent decode "#{string.escape_quotes}"
|
504
|
+
end tell
|
505
|
+
APPLESCRIPT`.strip
|
506
|
+
print result
|
507
|
+
end
|
508
|
+
end
|
data/lib/hook/string.rb
CHANGED
data/lib/hook/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
class ::Numeric
|
5
|
+
def pad_to(x)
|
6
|
+
"%0#{x.to_i}d" % self
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module HookHelpers
|
11
|
+
HOOK_EXEC = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'hook')
|
12
|
+
HOOK_FILES_DIR = File.join(File.dirname(__FILE__), '..', 'hookfiles')
|
13
|
+
HOOK_COMPLETIONS_DIR = File.join(File.dirname(__FILE__), '..', '..', 'lib', 'completion')
|
14
|
+
|
15
|
+
def create_temp_files
|
16
|
+
FileUtils.mkdir_p HOOK_FILES_DIR
|
17
|
+
10.times.with_index do |i|
|
18
|
+
new_file = File.join(HOOK_FILES_DIR, i.pad_to(2) + '.md')
|
19
|
+
File.open(new_file, 'w') do |f|
|
20
|
+
f.puts ("Hook Test File ##{i}")
|
21
|
+
end
|
22
|
+
hook('rm', '-a', '-f', new_file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def clean_temp_files
|
27
|
+
FileUtils.rm_r HOOK_FILES_DIR, force: true
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_count_links(file, count, msg)
|
31
|
+
res = hook('ls', file).strip
|
32
|
+
|
33
|
+
links = res == 'No bookmarks' ? 0 : res.split(/\n/).size
|
34
|
+
|
35
|
+
assert_equal(count, links, msg)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_links_include(file, pattern, msg)
|
39
|
+
result = hook('ls', file).strip
|
40
|
+
assert_match(/#{pattern}/, result, msg)
|
41
|
+
end
|
42
|
+
|
43
|
+
def hook(*args)
|
44
|
+
hook_with_env({}, *args)
|
45
|
+
end
|
46
|
+
|
47
|
+
def hook_with_stdin(input, *args)
|
48
|
+
pread_stdin({}, input, HOOK_EXEC, *args)
|
49
|
+
end
|
50
|
+
|
51
|
+
def hook_with_env(env, *args)
|
52
|
+
pread(env, HOOK_EXEC, *args)
|
53
|
+
end
|
54
|
+
|
55
|
+
def pread_stdin(env, input, *cmd)
|
56
|
+
out, err, status = Open3.capture3(env, 'bundle', 'exec', *cmd, :stdin_data => input)
|
57
|
+
unless status.success?
|
58
|
+
raise [
|
59
|
+
"Error (#{status}): #{cmd.inspect} failed", "STDOUT:", out.inspect, "STDERR:", err.inspect
|
60
|
+
].join("\n")
|
61
|
+
end
|
62
|
+
|
63
|
+
out
|
64
|
+
end
|
65
|
+
|
66
|
+
def pread(env, *cmd)
|
67
|
+
out, err, status = Open3.capture3(env, 'bundle', 'exec', *cmd)
|
68
|
+
unless status.success?
|
69
|
+
raise [
|
70
|
+
"Error (#{status}): #{cmd.inspect} failed", "STDOUT:", out.inspect, "STDERR:", err.inspect
|
71
|
+
].join("\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
out
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ClipTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@basedir = HOOK_FILES_DIR
|
9
|
+
create_temp_files
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
clean_temp_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_clip
|
17
|
+
file = Dir.glob(File.join(HOOK_FILES_DIR, '*.md'))[0]
|
18
|
+
# Clear clipboard
|
19
|
+
`echo -n | pbcopy`
|
20
|
+
hook('clip', file)
|
21
|
+
clipboard = `pbpaste`.strip
|
22
|
+
assert_match(/^hook:.*?#{File.basename(file)}$/, clipboard, 'Clipboard should contain link to first file')
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class CloneTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@basedir = HOOK_FILES_DIR
|
9
|
+
create_temp_files
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
clean_temp_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_clone
|
17
|
+
count = 3
|
18
|
+
|
19
|
+
files = Dir.glob(File.join(HOOK_FILES_DIR, '*.md'))
|
20
|
+
|
21
|
+
# Link all files to last file
|
22
|
+
hook('link', *files[0..count - 1])
|
23
|
+
links = hook('ls', files[count - 1]).strip
|
24
|
+
|
25
|
+
hook('clone', files[count-1], files[count])
|
26
|
+
cloned_links = hook('ls', files[count]).strip
|
27
|
+
|
28
|
+
assert_match(links, cloned_links, "#{files[count - 1]} links should match #{files[count]} links")
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class EncodeTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
# # FIXME: I don't know why this isn't getting output
|
14
|
+
# def test_encode_args
|
15
|
+
# result = hook('percent', 'encode', %(here's a "string?"))
|
16
|
+
# assert_match(/here%27s%20a%20%22string%3F%22/, result, 'URL encoded string should match')
|
17
|
+
# end
|
18
|
+
|
19
|
+
def test_encode_stdin
|
20
|
+
result = pread_stdin({}, %(here's a "string?"), HOOK_EXEC, 'percent', 'encode')
|
21
|
+
assert_match(/here%27s%20a%20%22string%3F%22/, result, 'URL encoded string should match')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_encode_decode_stdin
|
25
|
+
original_string = %(here's a "string?")
|
26
|
+
encoded = pread_stdin({}, original_string, HOOK_EXEC, 'percent', 'encode')
|
27
|
+
decoded = pread_stdin({}, encoded, HOOK_EXEC, 'percent', 'decode')
|
28
|
+
assert_match(decoded, original_string, 'URL encoded string should match')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class LinkTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@basedir = HOOK_FILES_DIR
|
9
|
+
create_temp_files
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
clean_temp_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_link
|
17
|
+
count = 3
|
18
|
+
|
19
|
+
files = Dir.glob(File.join(HOOK_FILES_DIR, '*.md'))[0..(count - 1)]
|
20
|
+
|
21
|
+
# Link all files to last file
|
22
|
+
hook('link', *files)
|
23
|
+
|
24
|
+
assert_count_links(files[-1], count - 1, "Last file should have #{count - 1} links")
|
25
|
+
assert_count_links(files[0], 1, 'First file should have 1 link')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_bi_link
|
29
|
+
count = 3
|
30
|
+
|
31
|
+
files = Dir.glob(File.join(HOOK_FILES_DIR, '*.md'))[0..(count - 1)]
|
32
|
+
|
33
|
+
# Link all files bi-directionally
|
34
|
+
hook('link', '-a', *files)
|
35
|
+
|
36
|
+
assert_count_links(files[-1], count - 1, "Last file should have #{count - 1} links")
|
37
|
+
assert_count_links(files[0], count - 1, "First file should have #{count - 1} links")
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ListTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@basedir = HOOK_FILES_DIR
|
9
|
+
create_temp_files
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
clean_temp_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_list
|
17
|
+
count = 2
|
18
|
+
files = Dir.glob(File.join(HOOK_FILES_DIR, '*.md'))[0..(count - 1)]
|
19
|
+
# Link all files to last file
|
20
|
+
hook('link', *files)
|
21
|
+
|
22
|
+
assert_count_links(files[-1], count - 1, "Last file should have #{count - 1} links")
|
23
|
+
assert_links_include(files[-1], File.basename(files[0]), 'Links on last file should include first file')
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class RemoveTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@basedir = HOOK_FILES_DIR
|
9
|
+
create_temp_files
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
clean_temp_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_remove
|
17
|
+
count = 5
|
18
|
+
|
19
|
+
files = Dir.glob(File.join(HOOK_FILES_DIR, '*.md'))[0..(count - 1)]
|
20
|
+
|
21
|
+
# Link all files to last file
|
22
|
+
hook('link', *files)
|
23
|
+
|
24
|
+
assert_count_links(files[-1], count - 1, "Last file should start with #{count - 1} links")
|
25
|
+
|
26
|
+
hook('remove', files[-1], files[0])
|
27
|
+
|
28
|
+
assert_count_links(files[-1], count - 2, "Last file should have #{count - 2} links")
|
29
|
+
|
30
|
+
hook('remove', '--all', '--force', files[-1])
|
31
|
+
|
32
|
+
assert_count_links(files[-1], 0, "Last file should end with 0 links")
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'hook-helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class EncodeTest < Test::Unit::TestCase
|
5
|
+
include HookHelpers
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_shell_scripts
|
14
|
+
%w[bash fish zsh].each do |sh|
|
15
|
+
source = IO.read(File.join(HOOK_COMPLETIONS_DIR, 'hook_completion.' + sh))
|
16
|
+
result = hook('scripts', sh)
|
17
|
+
|
18
|
+
assert_match(source, result, 'Script output should match')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|