hookapp 0.0.3 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +32 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +62 -28
  6. data/LICENSE.md +31 -0
  7. data/OVERVIEW.md +80 -0
  8. data/README.md +286 -23
  9. data/Rakefile +1 -1
  10. data/bin/hook +153 -20
  11. data/buildnotes.md +29 -0
  12. data/hook.rdoc +90 -9
  13. data/hookapp.gemspec +9 -8
  14. data/html/App.html +119 -0
  15. data/html/GLI.html +99 -0
  16. data/html/GLI/Commands.html +99 -0
  17. data/html/GLI/Commands/Doc.html +99 -0
  18. data/html/GLI/Commands/MarkdownDocumentListener.html +717 -0
  19. data/html/Hook.html +113 -0
  20. data/html/HookApp.html +1222 -0
  21. data/html/Hooker.html +119 -0
  22. data/html/README_rdoc.html +328 -0
  23. data/html/String.html +427 -0
  24. data/html/created.rid +9 -0
  25. data/html/css/fonts.css +167 -0
  26. data/html/css/rdoc.css +619 -0
  27. data/html/fonts/Lato-Light.ttf +0 -0
  28. data/html/fonts/Lato-LightItalic.ttf +0 -0
  29. data/html/fonts/Lato-Regular.ttf +0 -0
  30. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  31. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  32. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  33. data/html/images/add.png +0 -0
  34. data/html/images/arrow_up.png +0 -0
  35. data/html/images/brick.png +0 -0
  36. data/html/images/brick_link.png +0 -0
  37. data/html/images/bug.png +0 -0
  38. data/html/images/bullet_black.png +0 -0
  39. data/html/images/bullet_toggle_minus.png +0 -0
  40. data/html/images/bullet_toggle_plus.png +0 -0
  41. data/html/images/date.png +0 -0
  42. data/html/images/delete.png +0 -0
  43. data/html/images/find.png +0 -0
  44. data/html/images/loadingAnimation.gif +0 -0
  45. data/html/images/macFFBgHack.png +0 -0
  46. data/html/images/package.png +0 -0
  47. data/html/images/page_green.png +0 -0
  48. data/html/images/page_white_text.png +0 -0
  49. data/html/images/page_white_width.png +0 -0
  50. data/html/images/plugin.png +0 -0
  51. data/html/images/ruby.png +0 -0
  52. data/html/images/tag_blue.png +0 -0
  53. data/html/images/tag_green.png +0 -0
  54. data/html/images/transparent.png +0 -0
  55. data/html/images/wrench.png +0 -0
  56. data/html/images/wrench_orange.png +0 -0
  57. data/html/images/zoom.png +0 -0
  58. data/html/index.html +308 -0
  59. data/html/js/darkfish.js +84 -0
  60. data/html/js/navigation.js +105 -0
  61. data/html/js/navigation.js.gz +0 -0
  62. data/html/js/search.js +110 -0
  63. data/html/js/search_index.js +1 -0
  64. data/html/js/search_index.js.gz +0 -0
  65. data/html/js/searcher.js +229 -0
  66. data/html/js/searcher.js.gz +0 -0
  67. data/html/table_of_contents.html +409 -0
  68. data/lib/completion/hook_completion.bash +22 -0
  69. data/lib/completion/hook_completion.fish +31 -0
  70. data/lib/completion/hook_completion.zsh +22 -0
  71. data/lib/helpers/fuzzyfilefinder +0 -0
  72. data/lib/hook.rb +5 -1
  73. data/lib/hook/hookapp.rb +489 -0
  74. data/lib/hook/hooker.rb +1 -308
  75. data/lib/hook/markdown_document_listener.rb +164 -0
  76. data/lib/hook/string.rb +60 -0
  77. data/lib/hook/version.rb +3 -1
  78. metadata +87 -22
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'cucumber/rake/task'
7
7
  Rake::RDocTask.new do |rd|
8
8
  rd.main = "README.rdoc"
9
9
  rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
- rd.title = 'Your application title'
10
+ rd.title = 'hookapp'
11
11
  end
12
12
 
13
13
  spec = eval(File.read('hookapp.gemspec'))
data/bin/hook CHANGED
@@ -9,6 +9,10 @@ class App
9
9
  extend GLI::App
10
10
 
11
11
  program_desc 'CLI interface for Hook.app (macOS)'
12
+ program_long_desc 'Hook.app is a productivity tool for macOS <https://hookproductivity.com/>. This gem includes a `hook` binary that allows interaction with the features of Hook.app.'
13
+ default_command 'help'
14
+ autocomplete_commands = true
15
+ synopsis_format(:terminal)
12
16
 
13
17
  version Hook::VERSION
14
18
 
@@ -17,17 +21,18 @@ class App
17
21
 
18
22
  hooker = nil
19
23
 
20
- # desc 'Describe some switch here'
21
- # switch [:s,:switch]
24
+ desc 'List hooks on a file or url'
25
+ long_desc %{
26
+ Output a list of all hooks attached to given url(s) or file(s) in the specified format (default "paths").
22
27
 
23
- # desc 'Describe some flag here'
24
- # default_value 'the default'
25
- # arg_name 'The name of the argument'
26
- # flag [:f,:flagname]
28
+ Run `hook list` with no file/url argument to list all bookmarks.}
27
29
 
28
- desc 'List hooks on a file or url'
29
30
  arg_name 'FILE_OR_URL [FILE_OR_URL...]'
30
31
  command %i[list ls] do |c|
32
+ c.desc 'Generate a menu to select hook(s) for opening'
33
+ c.long_desc 'This option is a shortcut to `hook select` and overrides any other arguments.'
34
+ c.switch %i[s select]
35
+
31
36
  c.desc 'Output only bookmarks with file paths (exclude e.g. emails)'
32
37
  c.switch %i[f files_only], { negatable: false, default_value: false }
33
38
 
@@ -40,8 +45,11 @@ class App
40
45
  c.flag %i[o output_format], { arg_name: 'format', default_value: 'paths' }
41
46
 
42
47
  c.action do |_global_options, options, args|
48
+ if options[:s]
49
+ return hooker.open_linked(args[0])
50
+ end
43
51
  valid_format = hooker.validate_format(options[:o], valid_formats)
44
- raise 'Invalid output format' unless valid_format
52
+ exit_now!("Invalid output format: \"#{options[:o]}\"", 6) unless valid_format
45
53
 
46
54
  result = hooker.linked_bookmarks(args, { files_only: options[:f],
47
55
  format: valid_format,
@@ -51,7 +59,80 @@ class App
51
59
  end
52
60
  end
53
61
 
62
+ # Shell completion scripts are located in lib/completion/ and named "hook_completion" with
63
+ # the full shell name as the extension, e.g. "hook_completion.bash".
64
+ desc 'Shell completion examples'
65
+ valid_shells = %w[bash zsh fish]
66
+ long_desc %{
67
+ Output completion script example for the specified shell (#{valid_shells.join(', ')})
68
+ }
69
+ arg_name 'SHELL'
70
+ command %i[scripts] do |c|
71
+ c.action do |_global_options, _options, args|
72
+ if args.length > 1
73
+ exit_now!("Invalid number of arguments, (expected 1)", 5)
74
+ elsif args.nil? || args.empty?
75
+ exit_now!("Specify a shell (#{valid_shells.join(', ')})", 0)
76
+ else
77
+ if valid_shells.include?(args[0])
78
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), '../lib/completion'))
79
+ completion = File.join(base_dir, "hook_completion.#{args[0]}")
80
+ script = IO.read(completion)
81
+ $stdout.puts script
82
+ else
83
+ exit_now!("Invalid shell name, must be one of #{valid_shells.join(', ')}", 1)
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+
90
+
91
+ desc 'Search bookmarks'
92
+ long_desc %{
93
+ Search bookmark urls and names for a string and output in specified format (default "paths").
94
+
95
+ Run `hook find` with no search argument to list all bookmarks.}
96
+ arg_name 'SEARCH_STRING'
97
+ command %i[find search] do |c|
98
+ c.desc 'Output only bookmarks with file paths (exclude e.g. emails)'
99
+ c.switch %i[f files_only], { negatable: false, default_value: false }
100
+
101
+ c.desc 'Separate results with NULL separator, only applies with "paths" output for single file argument'
102
+ c.switch %i[null], { negatable: false, default_value: false }
103
+
104
+ valid_formats = %w[hooks paths markdown verbose]
105
+ fmt_list = valid_formats.map { |fmt| fmt.sub(/^(.)(.*?)$/, '(\1)\2') }.join(', ')
106
+
107
+ c.desc "Output format [#{fmt_list}]"
108
+ c.flag %i[o output_format], { arg_name: 'format', default_value: 'paths' }
109
+
110
+ c.desc "Search only bookmark names"
111
+ c.switch %i[n names_only], { negatable: false, default_value: false }
112
+
113
+ c.action do |_global_options, options, args|
114
+ valid_format = hooker.validate_format(options[:o], valid_formats)
115
+ exit_now!("Invalid output format: \"#{options[:o]}\"", 6) unless valid_format
116
+
117
+ result = hooker.search_bookmarks(args.join(" "), { files_only: options[:f],
118
+ format: valid_format,
119
+ null_separator: options[:null],
120
+ names_only: options[:n] })
121
+
122
+ puts result
123
+ end
124
+ end
125
+
54
126
  desc 'Create bidirectional hooks between two or more files/urls'
127
+ long_desc %{
128
+ If two files/urls are provided, links will be bi-directional.
129
+ If three or more are provided, `link` defaults to creating bi-directional
130
+ links between each file and the last file in the list. Use `-a` to create
131
+ bi-directional links between every file in the list.
132
+
133
+ If using `--paste`, the URL/hook link in the clipboard will be used as one argument,
134
+ to be combined with one or more file/url arguments.
135
+ }
55
136
  arg_name 'SOURCE [SOURCE...] TARGET'
56
137
  command %i[link ln] do |c|
57
138
  c.desc 'Link every listed file or url to every other'
@@ -67,7 +148,7 @@ class App
67
148
  args.push(clipboard) if clipboard
68
149
  end
69
150
  if args.length < 2
70
- raise 'At least 2 files must be specified, or one file with --paste'
151
+ exit_now!('Wrong number of arguments. At least 2 files must be specified, or one file with --paste', 5)
71
152
  end
72
153
  if options[:a]
73
154
  puts hooker.link_all(args)
@@ -78,34 +159,78 @@ class App
78
159
  end
79
160
 
80
161
  desc 'Copy Hook URL for file/url to clipboard'
162
+ long_desc %{
163
+ Creates a bookmark for the specified file or URL and copies its Hook URL to the clipboard.
164
+
165
+ The copied Hook URL can be used to link to other files (use `hook link --paste FILE/URL),
166
+ or to paste into another app as a link. Use the -m flag to copy a full Markdown link.
167
+ }
81
168
  arg_name 'FILE_OR_URL'
82
- command %i[clip] do |c|
169
+ command %i[clip cp] do |c|
83
170
  c.desc 'Copy as Markdown'
84
- c.switch %i[m markdown]
171
+ c.switch %i[m markdown], { negatable: false, default_value: false }
172
+
173
+ c.desc 'Copy from application'
174
+ c.flag %i[a app], { arg_name: 'APP_NAME' }
85
175
 
86
176
  c.action do |_global_options, options, args|
87
- result = hooker.copy_bookmark(args[0], { markdown: options[:m] })
88
- puts result
177
+ exit_now!('Wrong number of arguments. Requires a path/url or -a APP_NAME', 5) if args.length != 1 && !options[:a]
178
+
179
+ if options[:a]
180
+ puts hooker.bookmark_from_app(options[:a], { copy: true, markdown: options[:m] })
181
+ else
182
+ puts hooker.clip_bookmark(args[0], { markdown: options[:m] })
183
+ end
184
+ end
185
+ end
186
+
187
+ desc 'Get a Hook URL for the frontmost window of an app'
188
+ long_desc %{
189
+ Specify an application by name (without '.app') to bring that app to the foreground and create a bookmark
190
+ for the active document, note, task, etc., returning a Hook URL.
191
+
192
+ Use -m to get the response as Markdown, and/or -c to copy the result directly to the clipboard.
193
+ }
194
+ arg_name 'APPLICATION_NAME'
195
+ command %i[from] do |c|
196
+ c.desc 'Output as Markdown'
197
+ c.switch %i[m markdown], { negatable: false, default_value: false }
198
+
199
+ c.desc 'Copy to clipboard'
200
+ c.switch %i[c copy], { negatable: false, default_value: false }
201
+
202
+ c.action do |_global_options, options, args|
203
+ exit_now!("Wrong number of arguments (1 expected, #{args.length} given)", 5) if args.length != 1
204
+
205
+ puts hooker.bookmark_from_app(args[0], { copy: options[:c], markdown: options[:m] })
89
206
  end
90
207
  end
91
208
 
92
209
  desc 'Remove a hook between two files/urls'
210
+ long_desc %{
211
+ Remove a hook between two files or URLs. If you use --all, all hooks on a given file will be removed.
212
+
213
+ If --all isn't specified, exactly two arguments (Files/URLs) are required.
214
+ }
93
215
  arg_name 'ITEM_1 ITEM_2'
94
216
  command %i[remove rm] do |c|
95
217
  c.desc 'Remove ALL links on files, requires confirmation'
96
- c.switch %i[a all]
218
+ c.switch %i[a all], { negatable: false, default_value: false }
97
219
 
98
220
  c.action do |_global_options, options, args|
99
- result = hooker.delete_hooks(args, { all: options[:r] })
221
+ result = hooker.delete_hooks(args, { all: options[:a] })
100
222
  puts result
101
223
  end
102
224
  end
103
225
 
104
226
  desc 'Clone all hooks from one file or url onto another'
227
+ long_desc %{
228
+ Copy all the files and urls that the first file is hooked to onto another file. Exactly two arguments (SOURCE, TARGET) required.
229
+ }
105
230
  arg_name 'SOURCE TARGET'
106
- command %i[clone cp] do |c|
231
+ command %i[clone] do |c|
107
232
  c.action do |_global_options, _options, args|
108
- raise "Wrong number of arguments. Two file paths or urls required (#{args.length} given)" if args.length != 2
233
+ exit_now!("Wrong number of arguments. Two file paths or urls required (#{args.length} given)", 5) if args.length != 2
109
234
 
110
235
  result = hooker.clone_hooks(args)
111
236
  puts result
@@ -113,20 +238,28 @@ class App
113
238
  end
114
239
 
115
240
  desc 'Select from hooks on a file/url and open in default application'
241
+ long_desc %{
242
+ If the target file/URL has hooked items, a menu will be provided. Selecting one or more files
243
+ from this menu will open the item(s) using the default application assigned to the
244
+ filetype by macOS. Allows multiple selections with tab key, and type-ahead fuzzy filtering of results.
245
+ }
116
246
  arg_name 'FILE_OR_URL'
117
247
  command %i[select] do |c|
118
248
  c.action do |_global_options, _options, args|
119
- raise "Wrong number of arguments. One file path or url required (#{args.length} given)" if args.length != 1
249
+ exit_now!("Wrong number of arguments. One file path or url required (#{args.length} given)", 5) if args.length != 1
120
250
 
121
251
  hooker.open_linked(args[0])
122
252
  end
123
253
  end
124
254
 
125
255
  desc 'Open the specified file or url in Hook GUI'
256
+ long_desc %{
257
+ Opens Hook.app on the specified file/URL for browsing and performing actions. Exactly one argument (File/URL) required.
258
+ }
126
259
  arg_name 'FILE_OR_URL'
127
260
  command %i[open gui] do |c|
128
261
  c.action do |_global_options, _options, args|
129
- raise "Wrong number of arguments. One file path or url required (#{args.length} given)" if args.length != 1
262
+ exit_now!("Wrong number of arguments. One file path or url required (#{args.length} given)", 5) if args.length != 1
130
263
 
131
264
  hooker.open_gui(args[0])
132
265
  end
@@ -138,7 +271,7 @@ class App
138
271
  # chosen command
139
272
  # Use skips_pre before a command to skip this block
140
273
  # on that command only
141
- hooker = Hooker.new(global)
274
+ hooker = Hooker.new
142
275
  true
143
276
  end
144
277
 
@@ -0,0 +1,29 @@
1
+ # hookapp
2
+
3
+ Hook.app CLI
4
+
5
+ ## Editing
6
+
7
+ Main executable is located in `bin/hook`. All commands are defined here.
8
+
9
+ Helpers and main classes are in `lib/`.
10
+
11
+ @run(subl -p hookapp.sublime-project)
12
+
13
+ ## Building the Gem
14
+
15
+ @run(rake clobber rdoc package)
16
+
17
+ ## Deploy
18
+
19
+ 1. Bump version
20
+ 2. Commit and push to GitHub
21
+ 3. See Updating the Docs
22
+ 4. Package the gem (See Building the Gem)
23
+ 5. Push the gem with `gem push pkg/hookapp-[VERSION].gem`
24
+
25
+ ## Updating the Docs
26
+
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
+
29
+ @run(bundle exec bin/hook _doc --format=rdoc && bundle exec bin/hook _doc --format=markdown && rake rerdoc)
data/hook.rdoc CHANGED
@@ -1,6 +1,8 @@
1
1
  == hook - CLI interface for Hook.app (macOS)
2
2
 
3
- v0.0.2
3
+ Hook.app is a productivity tool for macOS <https://hookproductivity.com/>. This gem includes a `hook` binary that allows interaction with the features of Hook.app.
4
+
5
+ v2.0.3
4
6
 
5
7
  === Global Options
6
8
  === --help
@@ -14,19 +16,76 @@ Display the program version
14
16
 
15
17
 
16
18
  === Commands
17
- ==== Command: <tt>clip FILE_OR_URL</tt>
19
+ ==== Command: <tt>clip|cp FILE_OR_URL</tt>
18
20
  Copy Hook URL for file/url to clipboard
19
21
 
22
+ Creates a bookmark for the specified file or URL and copies its Hook URL to the clipboard.
20
23
 
24
+ The copied Hook URL can be used to link to other files (use `hook link --paste FILE/URL),
25
+ or to paste into another app as a link. Use the -m flag to copy a full Markdown link.
21
26
  ===== Options
22
- ===== -m|--[no-]markdown
27
+ ===== -a|--app APP_NAME
28
+
29
+ Copy from application
30
+
31
+ [Default Value] None
32
+
33
+
34
+ ===== -m|--markdown
23
35
  Copy as Markdown
24
36
 
25
37
 
26
38
 
27
- ==== Command: <tt>clone|cp SOURCE TARGET</tt>
39
+ ==== Command: <tt>clone SOURCE TARGET</tt>
28
40
  Clone all hooks from one file or url onto another
29
41
 
42
+ Copy all the files and urls that the first file is hooked to onto another file. Exactly two arguments (SOURCE, TARGET) required.
43
+ ==== Command: <tt>find|search SEARCH_STRING</tt>
44
+ Search bookmarks
45
+
46
+ Search bookmark urls and names for a string and output in specified format (default "paths").
47
+
48
+ Run `hook find` with no search argument to list all bookmarks.
49
+ ===== Options
50
+ ===== -o|--output_format format
51
+
52
+ Output format [(h)ooks, (p)aths, (m)arkdown, (v)erbose]
53
+
54
+ [Default Value] paths
55
+
56
+
57
+ ===== -f|--files_only
58
+ Output only bookmarks with file paths (exclude e.g. emails)
59
+
60
+
61
+
62
+ ===== -n|--names_only
63
+ Search only bookmark names
64
+
65
+
66
+
67
+ ===== --null
68
+ Separate results with NULL separator, only applies with "paths" output for single file argument
69
+
70
+
71
+
72
+ ==== Command: <tt>from APPLICATION_NAME</tt>
73
+ Get a Hook URL for the frontmost window of an app
74
+
75
+ Specify an application by name (without '.app') to bring that app to the foreground and create a bookmark
76
+ for the active document, note, task, etc., returning a Hook URL.
77
+
78
+ Use -m to get the response as Markdown, and/or -c to copy the result directly to the clipboard.
79
+ ===== Options
80
+ ===== -c|--copy
81
+ Copy to clipboard
82
+
83
+
84
+
85
+ ===== -m|--markdown
86
+ Output as Markdown
87
+
88
+
30
89
 
31
90
  ==== Command: <tt>help command</tt>
32
91
  Shows a list of commands or help for one command
@@ -38,10 +97,16 @@ List commands one per line, to assist with shell completion
38
97
 
39
98
 
40
99
 
41
- ==== Command: <tt>link|ln SOURCE [SOURCE, ...] TARGET</tt>
100
+ ==== Command: <tt>link|ln SOURCE [SOURCE...] TARGET</tt>
42
101
  Create bidirectional hooks between two or more files/urls
43
102
 
103
+ If two files/urls are provided, links will be bi-directional.
104
+ If three or more are provided, `link` defaults to creating bi-directional
105
+ links between each file and the last file in the list. Use `-a` to create
106
+ bi-directional links between every file in the list.
44
107
 
108
+ If using `--paste`, the URL/hook link in the clipboard will be used as one argument,
109
+ to be combined with one or more file/url arguments.
45
110
  ===== Options
46
111
  ===== -a|--all
47
112
  Link every listed file or url to every other
@@ -53,10 +118,12 @@ Paste URL from clipboard
53
118
 
54
119
 
55
120
 
56
- ==== Command: <tt>list|ls FILE_OR_URL [FILE_OR_URL, ...]</tt>
121
+ ==== Command: <tt>list|ls FILE_OR_URL [FILE_OR_URL...]</tt>
57
122
  List hooks on a file or url
58
123
 
124
+ Output a list of all hooks attached to given url(s) or file(s) in the specified format (default "paths").
59
125
 
126
+ Run `hook list` with no file/url argument to list all bookmarks.
60
127
  ===== Options
61
128
  ===== -o|--output_format format
62
129
 
@@ -75,21 +142,35 @@ Separate results with NULL separator, only applies with "paths" output for singl
75
142
 
76
143
 
77
144
 
145
+ ===== -s|--[no-]select
146
+ Generate a menu to select hook(s) for opening
147
+
148
+ This option is a shortcut to `hook select` and overrides any other arguments.
149
+
78
150
  ==== Command: <tt>open|gui FILE_OR_URL</tt>
79
151
  Open the specified file or url in Hook GUI
80
152
 
81
-
153
+ Opens Hook.app on the specified file/URL for browsing and performing actions. Exactly one argument (File/URL) required.
82
154
  ==== Command: <tt>remove|rm ITEM_1 ITEM_2</tt>
83
155
  Remove a hook between two files/urls
84
156
 
157
+ Remove a hook between two files or URLs. If you use --all, all hooks on a given file will be removed.
85
158
 
159
+ If --all isn't specified, exactly two arguments (Files/URLs) are required.
86
160
  ===== Options
87
- ===== -a|--[no-]all
161
+ ===== -a|--all
88
162
  Remove ALL links on files, requires confirmation
89
163
 
90
164
 
91
165
 
166
+ ==== Command: <tt>scripts SHELL</tt>
167
+ Shell completion examples
168
+
169
+ Output completion script example for the specified shell (bash, zsh, fish)
92
170
  ==== Command: <tt>select FILE_OR_URL</tt>
93
171
  Select from hooks on a file/url and open in default application
94
172
 
95
-
173
+ If the target file/URL has hooked items, a menu will be provided. Selecting one or more files
174
+ from this menu will open the item(s) using the default application assigned to the
175
+ filetype by macOS. Allows multiple selections with tab key, and type-ahead fuzzy filtering of results.
176
+ [Default Command] help