bunchcli 1.1.5 → 1.1.11.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +2 -2
- data/Gemfile +0 -1
- data/lib/bunch.rb +3 -1
- data/lib/bunch/bunchCLI.rb +25 -15
- data/lib/bunch/url_generator.rb +31 -15
- data/lib/bunch/version.rb +1 -1
- metadata +5 -6
- data/Gemfile.lock +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70d3422a46d0fcef92ba107d45988048e87861e7c43850804ae8f694fc68073a
|
4
|
+
data.tar.gz: d0e9a81d6681c68440171064ee6b43890848ae3a598fe5824ac4d879a57de8e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5f34bb75d84b59e86ed3646a30f5ef86d90ff7e6cf91fac65a31bbc9d505d8b0944c61e2d4f3445504893639f7591ed0b9dc31a2aa17cf7392a0c7585e9663
|
7
|
+
data.tar.gz: 27a8b4693967cc09fd11036caa1162454a393907fff8036f6c8decb4ec47759d758dbc8e59201a797c6978df9d9e066d08e0d085edadfe1cc73adc1b37e0ba39
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/bunch.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
CACHE_TIME = 86400 #seconds, 1 day = 86400
|
2
2
|
CACHE_FILE = "~/.bunch_cli_cache"
|
3
|
+
TARGET_APP = "Bunch Beta"
|
4
|
+
|
5
|
+
TARGET_URL = TARGET_APP == 'Bunch Beta' ? 'x-bunch-beta' : 'x-bunch'
|
3
6
|
|
4
7
|
require "bunch/version"
|
5
8
|
require 'yaml'
|
6
9
|
require 'cgi'
|
7
10
|
require 'bunch/url_generator'
|
8
|
-
require 'term-colorizer'
|
9
11
|
require 'bunch/bunchCLI'
|
data/lib/bunch/bunchCLI.rb
CHANGED
@@ -69,10 +69,11 @@ class Bunch
|
|
69
69
|
# items.push({title: 0})
|
70
70
|
def generate_bunch_list
|
71
71
|
items = []
|
72
|
-
|
72
|
+
`osascript -e 'tell app "#{TARGET_APP}" to list bunches'`.strip.split(/,/).each do |b|
|
73
|
+
b.strip!
|
73
74
|
items.push(
|
74
|
-
path:
|
75
|
-
title:
|
75
|
+
path: File.join(bunch_dir, b + '.bunch'),
|
76
|
+
title: b
|
76
77
|
)
|
77
78
|
end
|
78
79
|
items
|
@@ -80,13 +81,15 @@ class Bunch
|
|
80
81
|
|
81
82
|
def bunch_dir
|
82
83
|
@bunch_dir ||= begin
|
83
|
-
dir =
|
84
|
+
dir = `osascript -e 'tell app "#{TARGET_APP}" to get preference "Folder"'`.strip
|
85
|
+
# dir = `/usr/bin/defaults read #{ENV['HOME']}/Library/Preferences/com.brettterpstra.Bunch.plist configDir`.strip
|
84
86
|
File.expand_path(dir)
|
85
87
|
end
|
86
88
|
end
|
87
89
|
|
88
90
|
def url_method
|
89
|
-
@url_method ||=
|
91
|
+
@url_method ||= `osascript -e 'tell app "#{TARGET_APP}" to get preference "Toggle"'`.strip == '1' ? 'toggle' : 'open'
|
92
|
+
# @url_method ||= `/usr/bin/defaults read #{ENV['HOME']}/Library/Preferences/com.brettterpstra.Bunch.plist toggleBunches`.strip == '1' ? 'toggle' : 'open'
|
90
93
|
end
|
91
94
|
|
92
95
|
def bunches
|
@@ -96,15 +99,15 @@ class Bunch
|
|
96
99
|
def url(bunch)
|
97
100
|
params = "&x-success=#{@success}" if @success
|
98
101
|
if url_method == 'file'
|
99
|
-
%(
|
102
|
+
%(#{TARGET_URL}://raw?file=#{bunch}#{params})
|
100
103
|
elsif url_method == 'raw'
|
101
|
-
%(
|
104
|
+
%(#{TARGET_URL}://raw?txt=#{bunch}#{params})
|
102
105
|
elsif url_method == 'snippet'
|
103
|
-
%(
|
106
|
+
%(#{TARGET_URL}://snippet?file=#{bunch}#{params})
|
104
107
|
elsif url_method == 'setPref'
|
105
|
-
%(
|
108
|
+
%(#{TARGET_URL}://setPref?#{bunch})
|
106
109
|
else
|
107
|
-
%(
|
110
|
+
%(#{TARGET_URL}://#{url_method}?bunch=#{bunch}#{params})
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
@@ -150,7 +153,7 @@ EOF
|
|
150
153
|
launch_if_needed
|
151
154
|
# get front app
|
152
155
|
front_app = %x{osascript -e 'tell application "System Events" to return name of first application process whose frontmost is true'}.strip
|
153
|
-
bid = bundle_id(front_app)
|
156
|
+
bid = bundle_id(front_app) rescue false
|
154
157
|
@success = bid if (bid)
|
155
158
|
|
156
159
|
if @url_method == 'raw'
|
@@ -187,25 +190,32 @@ EOF
|
|
187
190
|
end
|
188
191
|
else
|
189
192
|
bunch = find_bunch(str)
|
193
|
+
params = []
|
194
|
+
params << "fragment=#{CGI.escape(@fragment)}" if @fragment
|
195
|
+
params.concat(variable_query) if @variables
|
190
196
|
unless bunch
|
191
197
|
if File.exists?(str)
|
192
198
|
@url_method = 'file'
|
199
|
+
_url = url(str)
|
200
|
+
_url += '&' + params.join('&') if params.length
|
193
201
|
if @show_url
|
194
|
-
$stdout.puts
|
202
|
+
$stdout.puts _url
|
195
203
|
else
|
196
204
|
warn "Opening file"
|
197
|
-
`open '#{
|
205
|
+
`open '#{_url}'`
|
198
206
|
end
|
199
207
|
else
|
200
208
|
warn 'No matching Bunch found'
|
201
209
|
Process.exit 1
|
202
210
|
end
|
203
211
|
else
|
212
|
+
_url = url(bunch[:title])
|
213
|
+
_url += '&' + params.join('&') if params.length
|
204
214
|
if @show_url
|
205
|
-
$stdout.puts
|
215
|
+
$stdout.puts _url
|
206
216
|
else
|
207
217
|
warn "#{human_action} #{bunch[:title]}"
|
208
|
-
`open '#{
|
218
|
+
`open '#{_url}'`
|
209
219
|
end
|
210
220
|
end
|
211
221
|
end
|
data/lib/bunch/url_generator.rb
CHANGED
@@ -15,9 +15,17 @@ end
|
|
15
15
|
module Util
|
16
16
|
def bundle_id(app)
|
17
17
|
shortname = app.sub(/\.app$/, '')
|
18
|
-
apps = `mdfind -onlyin /Applications -onlyin /Applications/Setapp -onlyin /Applications/Utilities -onlyin ~/Applications -onlyin /Developer/Applications 'kMDItemKind==Application'`
|
18
|
+
apps = `mdfind -onlyin /Applications -onlyin /Applications/Setapp -onlyin /Applications/Utilities -onlyin ~/Applications -onlyin /Developer/Applications -onlyin /System/Applications 'kMDItemKind==Application'`
|
19
19
|
|
20
|
-
|
20
|
+
return false if !apps || apps.strip.length == 0
|
21
|
+
|
22
|
+
foundapps = apps.split(/\n/).select! { |line| line.chomp =~ /#{shortname}\.app$/i }
|
23
|
+
|
24
|
+
if foundapps.length > 0
|
25
|
+
foundapp = foundapps[0]
|
26
|
+
else
|
27
|
+
return false
|
28
|
+
end
|
21
29
|
|
22
30
|
if foundapp
|
23
31
|
bid = `mdls -name kMDItemCFBundleIdentifier -r "#{foundapp}"`.chomp
|
@@ -49,8 +57,7 @@ module Prompt
|
|
49
57
|
def get_line(query = '->')
|
50
58
|
stty_save = `stty -g`.chomp
|
51
59
|
begin
|
52
|
-
|
53
|
-
line = Readline.readline(": ", true)
|
60
|
+
line = Readline.readline("#{query}: ", true)
|
54
61
|
rescue Interrupt
|
55
62
|
system('stty', stty_save) # Restore
|
56
63
|
exit
|
@@ -61,7 +68,7 @@ module Prompt
|
|
61
68
|
def get_text(query = 'Enter text, ^d to end')
|
62
69
|
stty_save = `stty -g`.chomp
|
63
70
|
lines = []
|
64
|
-
puts query
|
71
|
+
puts query
|
65
72
|
begin
|
66
73
|
while (line = Readline.readline)
|
67
74
|
lines << line
|
@@ -103,15 +110,15 @@ class Menu
|
|
103
110
|
def choose(query = 'Select an item')
|
104
111
|
throw 'No items initialized' if @items.nil?
|
105
112
|
STDERR.puts
|
106
|
-
STDERR.puts "┌#{("─" * 74)}┐"
|
113
|
+
STDERR.puts "┌#{("─" * 74)}┐"
|
107
114
|
intpad = Math::log10(@items.length).to_i + 1
|
108
115
|
@items.each_with_index do |item, idx|
|
109
116
|
idxstr = "%#{intpad}d" % (idx + 1)
|
110
117
|
line = "#{idxstr}: #{item.title}"
|
111
118
|
pad = 74 - line.length
|
112
|
-
STDERR.puts "
|
119
|
+
STDERR.puts "│#{line}#{" " * pad}│"
|
113
120
|
end
|
114
|
-
STDERR.puts "└┤
|
121
|
+
STDERR.puts "└┤ #{query} ├#{"─" * (70 - query.length)}┘"
|
115
122
|
sel = choose_number("> ", @items.length)
|
116
123
|
sel ? @items[sel.to_i - 1] : nil
|
117
124
|
end
|
@@ -159,7 +166,7 @@ class BunchFinder
|
|
159
166
|
attr_accessor :config_dir
|
160
167
|
|
161
168
|
def initialize
|
162
|
-
config_dir = `
|
169
|
+
config_dir = `osascript -e 'tell app "#{TARGET_APP}" to get preference "Folder"'`.strip
|
163
170
|
config_dir = File.expand_path(config_dir)
|
164
171
|
if File.directory?(config_dir)
|
165
172
|
@config_dir = config_dir
|
@@ -168,6 +175,15 @@ class BunchFinder
|
|
168
175
|
end
|
169
176
|
end
|
170
177
|
|
178
|
+
def bunches_to_items
|
179
|
+
items = []
|
180
|
+
`osascript -e 'tell app "#{TARGET_APP}" to list bunches'`.strip.split(/,/).each do |b|
|
181
|
+
filename = b.strip
|
182
|
+
items << MenuItem.new(filename, filename, filename)
|
183
|
+
end
|
184
|
+
items
|
185
|
+
end
|
186
|
+
|
171
187
|
def files_to_items(dir, pattern)
|
172
188
|
Dir.chdir(dir)
|
173
189
|
items = []
|
@@ -181,12 +197,12 @@ class BunchFinder
|
|
181
197
|
end
|
182
198
|
|
183
199
|
def choose_bunch
|
184
|
-
items =
|
185
|
-
items.map! do |item|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
200
|
+
items = bunches_to_items
|
201
|
+
# items.map! do |item|
|
202
|
+
# item.title = File.basename(item.title, '.bunch')
|
203
|
+
# item.value = File.basename(item.title, '.bunch')
|
204
|
+
# item
|
205
|
+
# end
|
190
206
|
menu = Menu.new(items)
|
191
207
|
menu.choose('Select a Bunch')
|
192
208
|
end
|
data/lib/bunch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunchcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.11.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -21,7 +21,6 @@ files:
|
|
21
21
|
- ".gitignore"
|
22
22
|
- CHANGELOG.md
|
23
23
|
- Gemfile
|
24
|
-
- Gemfile.lock
|
25
24
|
- LICENSE.txt
|
26
25
|
- README.md
|
27
26
|
- Rakefile
|
@@ -49,11 +48,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
48
|
version: 2.0.0
|
50
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
|
-
- - "
|
51
|
+
- - ">"
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
53
|
+
version: 1.3.1
|
55
54
|
requirements: []
|
56
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.2.16
|
57
56
|
signing_key:
|
58
57
|
specification_version: 4
|
59
58
|
summary: A CLI for use with Bunch.app (macOS)
|
data/Gemfile.lock
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bunchcli (1.1.4)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
rake (12.3.3)
|
10
|
-
term-colorizer (0.2.1)
|
11
|
-
|
12
|
-
PLATFORMS
|
13
|
-
x86_64-darwin-19
|
14
|
-
|
15
|
-
DEPENDENCIES
|
16
|
-
bunchcli!
|
17
|
-
rake (~> 12.0)
|
18
|
-
term-colorizer
|
19
|
-
|
20
|
-
BUNDLED WITH
|
21
|
-
2.2.4
|