hookapp 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2823ba5fc9c9745eae3ab91e6bf0b27a88b8a030931e3c07c305d2c4aca52a70
4
- data.tar.gz: fe130f18aac896e3058361fe26ee182cc4047c4db10e61df19c24bd24d715f87
3
+ metadata.gz: af7f2f009d2c02cad8385099d036499770fc256c7ee62f54bb154dddef391450
4
+ data.tar.gz: a57bea2c1682d71e5f37f95ef81f2cc20a25f18b53febbc29630abd2d73dfa9a
5
5
  SHA512:
6
- metadata.gz: e35a77b9bc373266a5a26e653b9ad20ae2446d4ff9571fa56c054ba4bb782d4737f25d00294db5449534cc5482d94c8268b815c26799158709adc5314de10b18
7
- data.tar.gz: f7659543f1fcda1e9f1183f071a469a1fe4e3b1bb22d68945630c652fb33194ae12e9d940504b8aff15e70e16136e6fdad56f1225c1172558e1916eb65c480b8
6
+ metadata.gz: fd32ce6c7e9348e398acce8988f2e50a762d2cf4dae21e3a3c02d1f2310371a8c79b22bda56e60bd5398329769b66f5a94cf6af95c4d1701e489cbd7f9cdc8a3
7
+ data.tar.gz: 0e4d669d29e3121ac1f7411550b853abf5bafc32d05fd480892e4276a74af4c310aa9d4afa9aadab4ab99164badfb4146a8343ea4e5212a803fbcd34aa570d2b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hookapp (0.0.3)
4
+ hookapp (0.0.4)
5
5
  gli (= 2.19.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -28,6 +28,7 @@ Run `hook help` for usage:
28
28
  COMMANDS
29
29
  clip - Copy Hook URL for file/url to clipboard
30
30
  clone, cp - Clone all hooks from one file or url onto another
31
+ from - Get a Hook URL for the frontmost window of an app
31
32
  help - Shows a list of commands or help for one command
32
33
  link, ln - Create bidirectional hooks between two or more files/urls
33
34
  list, ls - List hooks on a file or url
@@ -67,6 +68,11 @@ You can also open a file in the Hook GUI using `hook open file1.md`.
67
68
 
68
69
  ### Changelog
69
70
 
71
+ #### 0.0.5
72
+
73
+ - `hook from APP_NAME` command
74
+ - General code cleanup
75
+
70
76
  #### 0.0.4
71
77
 
72
78
  - Fix "conversion of nil into string" error
data/bin/hook CHANGED
@@ -17,14 +17,6 @@ class App
17
17
 
18
18
  hooker = nil
19
19
 
20
- # desc 'Describe some switch here'
21
- # switch [:s,:switch]
22
-
23
- # desc 'Describe some flag here'
24
- # default_value 'the default'
25
- # arg_name 'The name of the argument'
26
- # flag [:f,:flagname]
27
-
28
20
  desc 'List hooks on a file or url'
29
21
  arg_name 'FILE_OR_URL [FILE_OR_URL...]'
30
22
  command %i[list ls] do |c|
@@ -81,11 +73,35 @@ class App
81
73
  arg_name 'FILE_OR_URL'
82
74
  command %i[clip] do |c|
83
75
  c.desc 'Copy as Markdown'
84
- c.switch %i[m markdown]
76
+ c.switch %i[m markdown], { negatable: false, default_value: false }
77
+
78
+ c.desc 'Copy from application'
79
+ c.flag %i[a app], { arg_name: 'APP_NAME' }
85
80
 
86
81
  c.action do |_global_options, options, args|
87
- result = hooker.copy_bookmark(args[0], { markdown: options[:m] })
88
- puts result
82
+ raise 'Wrong number of arguments. Requires a path/url or -a APP_NAME' if args.length != 1 && !options[:a]
83
+
84
+ if options[:a]
85
+ puts hooker.bookmark_from_app(options[:a], { copy: true, markdown: options[:m] })
86
+ else
87
+ puts hooker.clip_bookmark(args[0], { markdown: options[:m] })
88
+ end
89
+ end
90
+ end
91
+
92
+ desc 'Get a Hook URL for the frontmost window of an app'
93
+ arg_name 'APPLICATION_NAME'
94
+ command %i[from] do |c|
95
+ c.desc 'Output as Markdown'
96
+ c.switch %i[m markdown], { negatable: false, default_value: false }
97
+
98
+ c.desc 'Copy to clipboard'
99
+ c.switch %i[c copy], { negatable: false, default_value: false }
100
+
101
+ c.action do |_global_options, options, args|
102
+ raise "Wrong number of arguments (1 expected, #{args.length} given)" if args.length != 1
103
+
104
+ puts hooker.bookmark_from_app(args[0], { copy: options[:c], markdown: options[:m] })
89
105
  end
90
106
  end
91
107
 
data/hook.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  == hook - CLI interface for Hook.app (macOS)
2
2
 
3
- v0.0.2
3
+ v0.0.4
4
4
 
5
5
  === Global Options
6
6
  === --help
@@ -19,7 +19,14 @@ Copy Hook URL for file/url to clipboard
19
19
 
20
20
 
21
21
  ===== Options
22
- ===== -m|--[no-]markdown
22
+ ===== -a|--app APP_NAME
23
+
24
+ Copy from application
25
+
26
+ [Default Value] None
27
+
28
+
29
+ ===== -m|--markdown
23
30
  Copy as Markdown
24
31
 
25
32
 
@@ -28,6 +35,21 @@ Copy as Markdown
28
35
  Clone all hooks from one file or url onto another
29
36
 
30
37
 
38
+ ==== Command: <tt>from APPLICATION_NAME</tt>
39
+ Get a Hook URL for the frontmost window of an app
40
+
41
+
42
+ ===== Options
43
+ ===== -c|--copy
44
+ Copy to clipboard
45
+
46
+
47
+
48
+ ===== -m|--markdown
49
+ Output as Markdown
50
+
51
+
52
+
31
53
  ==== Command: <tt>help command</tt>
32
54
  Shows a list of commands or help for one command
33
55
 
@@ -38,7 +60,7 @@ List commands one per line, to assist with shell completion
38
60
 
39
61
 
40
62
 
41
- ==== Command: <tt>link|ln SOURCE [SOURCE, ...] TARGET</tt>
63
+ ==== Command: <tt>link|ln SOURCE [SOURCE...] TARGET</tt>
42
64
  Create bidirectional hooks between two or more files/urls
43
65
 
44
66
 
@@ -53,7 +75,7 @@ Paste URL from clipboard
53
75
 
54
76
 
55
77
 
56
- ==== Command: <tt>list|ls FILE_OR_URL [FILE_OR_URL, ...]</tt>
78
+ ==== Command: <tt>list|ls FILE_OR_URL [FILE_OR_URL...]</tt>
57
79
  List hooks on a file or url
58
80
 
59
81
 
@@ -29,6 +29,26 @@ class String
29
29
  def valid_hook!
30
30
  replace valid_hook
31
31
  end
32
+
33
+ # Capitalize only if no uppercase
34
+ def cap
35
+ unless self =~ /[A-Z]/
36
+ capitalize
37
+ else
38
+ self
39
+ end
40
+ end
41
+
42
+ def cap!
43
+ replace cap
44
+ end
45
+
46
+ def clip
47
+ res = `/bin/echo -n #{Shellwords.escape(self)} | pbcopy`.strip
48
+ raise "Failed to copy to clipboard" unless res.empty?
49
+
50
+ true
51
+ end
32
52
  end
33
53
 
34
54
  # Hook.app CLI interface
@@ -85,15 +105,39 @@ class Hooker
85
105
  hooks.split_hooks
86
106
  end
87
107
 
88
- def copy_bookmark(url, opts)
108
+ def bookmark_from_app(app, opts)
109
+ mark = `osascript <<'APPLESCRIPT'
110
+ tell application "System Events" to set front_app to name of first application process whose frontmost is true
111
+ tell application "#{app}" to activate
112
+ delay 2
113
+ tell application "Hook"
114
+ set _hook to (bookmark from active window)
115
+ set _output to (title of _hook & "||" & address of _hook & "||" & path of _hook)
116
+ end tell
117
+ tell application front_app to activate
118
+ return _output
119
+ APPLESCRIPT`.strip.split_hook
120
+ title = mark[:name].empty? ? "#{app.cap} link" : mark[:name]
121
+ output = opts[:markdown] ? "[#{title}](#{mark[:url]})" : mark[:url]
122
+
123
+ if opts[:copy]
124
+ "Copied Markdown link for '#{title}' to clipboard" if output.clip
125
+ else
126
+ output
127
+ end
128
+ end
129
+
130
+ def clip_bookmark(url, opts)
89
131
  mark = bookmark_for(url)
90
- output = if opts[:markdown]
91
- "[#{mark[:name]}](#{mark[:url]})"
92
- else
93
- mark[:url]
94
- end
95
- `/bin/echo -n #{Shellwords.escape(output)} | pbcopy`
96
- %(Copied #{opts[:markdown] ? 'Markdown link' : 'Hook URL'} for '#{mark[:name]}' to clipboard)
132
+ copy_bookmark(mark[:name], mark[:url], opts)
133
+ end
134
+
135
+ def copy_bookmark(title, url, opts)
136
+ raise "No URL found" if url.empty?
137
+ title = title.empty? ? 'No title' : mark[:name]
138
+ output = opts[:markdown] ? "[#{title}](#{url})" : url
139
+ output.clip
140
+ %(Copied #{opts[:markdown] ? 'Markdown link' : 'Hook URL'} for '#{title}' to clipboard)
97
141
  end
98
142
 
99
143
  def select_hook(marks)
@@ -103,12 +147,9 @@ class Hooker
103
147
  end
104
148
  STDERR.print 'Open which bookmark: '
105
149
  sel = STDIN.gets.strip.to_i
106
- if sel.positive? && sel <= marks.length
107
- marks[sel - 1]
108
- else
109
- warn 'Invalid selection'
110
- Process.exit 1
111
- end
150
+ raise 'Invalid selection' unless sel.positive? && sel <= marks.length
151
+
152
+ marks[sel - 1]
112
153
  end
113
154
 
114
155
  def open_gui(url)
@@ -1,3 +1,3 @@
1
1
  module Hook
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra