bunchcli 1.1.9.pre → 1.1.10.pre

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: 0a0125c6936b9621c4d8252a1df185e668c8dc85c8d6ed563fd203f7f018a475
4
- data.tar.gz: ef01962a5939067128ffd5024055561b60ee8118e09216065e3642e0a9f33c6c
3
+ metadata.gz: dcda55808cd36cb2a58d47e7d6e0c0fa10772305ab8334bbd40d7f08f38949ae
4
+ data.tar.gz: 867e15277ae14bb607337e3bcba90192359bc89747450ec2abd526e441fd825f
5
5
  SHA512:
6
- metadata.gz: 282e71d31323a1496eb98f6f06e360ca8a5564f004da13ceda9939ddf2cc5b5bc3bda694250e598f51d398796ff598461e0d9250600a1e931d332f924fa7d03a
7
- data.tar.gz: a202098f10ef8da9c3017c5c7e61e342b59dfef5cd3cb8c6fb8725cb49923b42ff430fcc23ff4a405e57ac3cb308927d7191ac1c2c8075761629c8c6a9644a3a
6
+ metadata.gz: 13e69c1cbb174fc1422a6480c96a016067fda4f44fb36a8a711cd3903423ee9b7a441deacd2995ff92f8fbc945c3a3b0dfd0c35e92944cb9bb4eea3713c0bb71
7
+ data.tar.gz: a7a76acbe1021ca87bad1fad48c8c06b70095d9db73b2c8368ffe157e49eff9ffc828185fa6c0b750f98fb37face66237df24f57b4ea7f79855e5cf43f8d6613
data/bin/bunch CHANGED
@@ -18,10 +18,6 @@ bunch = Bunch.new
18
18
  optparse = OptionParser.new do |opts|
19
19
  opts.banner = "CLI for Bunch.app v#{BunchCLI::VERSION}"
20
20
 
21
- opts.on('-b', '--beta', 'Use Bunch Beta for commands') do |_opt|
22
- bunch.target_app = 'Bunch Beta'
23
- end
24
-
25
21
  opts.on('-l', '--list', 'List available Bunches') do |_opt|
26
22
  bunch.list_bunches
27
23
  Process.exit 0
data/lib/bunch.rb CHANGED
@@ -1,5 +1,8 @@
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'
@@ -1,9 +1,8 @@
1
1
  class Bunch
2
2
  include Util
3
- attr_writer :target_app, :url_method, :fragment, :variables, :show_url
3
+ attr_writer :url_method, :fragment, :variables, :show_url
4
4
 
5
5
  def initialize
6
- @target_app = nil
7
6
  @bunch_dir = nil
8
7
  @url_method = nil
9
8
  @bunches = nil
@@ -26,13 +25,11 @@ class Bunch
26
25
  @bunch_dir = nil
27
26
  @url_method = nil
28
27
  @bunches = nil
29
- @target_app = nil
30
28
  target = File.expand_path(CACHE_FILE)
31
29
  settings = {
32
30
  'bunchDir' => bunch_dir,
33
31
  'method' => url_method,
34
32
  'bunches' => bunches,
35
- 'target_app' => target_app,
36
33
  'updated' => Time.now.strftime('%s').to_i
37
34
  }
38
35
  File.open(target,'w') do |f|
@@ -55,7 +52,6 @@ class Bunch
55
52
  @bunch_dir = settings['bunchDir'] || bunch_dir
56
53
  @url_method = settings['method'] || url_method
57
54
  @bunches = settings['bunches'] || generate_bunch_list
58
- @target_app = settings['target_app'] || target_app
59
55
  end
60
56
 
61
57
  def variable_query
@@ -73,10 +69,11 @@ class Bunch
73
69
  # items.push({title: 0})
74
70
  def generate_bunch_list
75
71
  items = []
76
- Dir.glob(File.join(bunch_dir, '**/*.bunch')).each do |f|
72
+ `osascript -e 'tell app "#{TARGET_APP}" to list bunches'`.strip.split(/,/).each do |b|
73
+ b.strip!
77
74
  items.push(
78
- path: f,
79
- title: f.sub(/^#{bunch_dir}\//,'').sub(/\.bunch$/,'')
75
+ path: File.join(bunch_dir, b + '.bunch'),
76
+ title: b
80
77
  )
81
78
  end
82
79
  items
@@ -84,18 +81,14 @@ class Bunch
84
81
 
85
82
  def bunch_dir
86
83
  @bunch_dir ||= begin
87
- dir = `osascript -e 'tell app "#{@target_app}" to get preference "Folder"'`.strip
84
+ dir = `osascript -e 'tell app "#{TARGET_APP}" to get preference "Folder"'`.strip
88
85
  # dir = `/usr/bin/defaults read #{ENV['HOME']}/Library/Preferences/com.brettterpstra.Bunch.plist configDir`.strip
89
86
  File.expand_path(dir)
90
87
  end
91
88
  end
92
89
 
93
- def target_app
94
- @target_app ||= "Bunch"
95
- end
96
-
97
90
  def url_method
98
- @url_method ||= `osascript -e 'tell app "#{@target_app}" to get preference "Toggle"'`.strip == '1' ? 'toggle' : 'open'
91
+ @url_method ||= `osascript -e 'tell app "#{TARGET_APP}" to get preference "Toggle"'`.strip == '1' ? 'toggle' : 'open'
99
92
  # @url_method ||= `/usr/bin/defaults read #{ENV['HOME']}/Library/Preferences/com.brettterpstra.Bunch.plist toggleBunches`.strip == '1' ? 'toggle' : 'open'
100
93
  end
101
94
 
@@ -106,15 +99,15 @@ class Bunch
106
99
  def url(bunch)
107
100
  params = "&x-success=#{@success}" if @success
108
101
  if url_method == 'file'
109
- %(x-bunch://raw?file=#{bunch}#{params})
102
+ %(#{TARGET_URL}://raw?file=#{bunch}#{params})
110
103
  elsif url_method == 'raw'
111
- %(x-bunch://raw?txt=#{bunch}#{params})
104
+ %(#{TARGET_URL}://raw?txt=#{bunch}#{params})
112
105
  elsif url_method == 'snippet'
113
- %(x-bunch://snippet?file=#{bunch}#{params})
106
+ %(#{TARGET_URL}://snippet?file=#{bunch}#{params})
114
107
  elsif url_method == 'setPref'
115
- %(x-bunch://setPref?#{bunch})
108
+ %(#{TARGET_URL}://setPref?#{bunch})
116
109
  else
117
- %(x-bunch://#{url_method}?bunch=#{bunch[:title]}#{params})
110
+ %(#{TARGET_URL}://#{url_method}?bunch=#{bunch}#{params})
118
111
  end
119
112
  end
120
113
 
@@ -197,25 +190,32 @@ EOF
197
190
  end
198
191
  else
199
192
  bunch = find_bunch(str)
193
+ params = []
194
+ params << "fragment=#{CGI.escape(@fragment)}" if @fragment
195
+ params.concat(variable_query) if @variables
200
196
  unless bunch
201
197
  if File.exists?(str)
202
198
  @url_method = 'file'
199
+ _url = url(str)
200
+ _url += '&' + params.join('&') if params.length
203
201
  if @show_url
204
- $stdout.puts url(str)
202
+ $stdout.puts _url
205
203
  else
206
204
  warn "Opening file"
207
- `open '#{url(str)}'`
205
+ `open '#{_url}'`
208
206
  end
209
207
  else
210
208
  warn 'No matching Bunch found'
211
209
  Process.exit 1
212
210
  end
213
211
  else
212
+ _url = url(bunch[:title])
213
+ _url += '&' + params.join('&') if params.length
214
214
  if @show_url
215
- $stdout.puts url(str)
215
+ $stdout.puts _url
216
216
  else
217
217
  warn "#{human_action} #{bunch[:title]}"
218
- `open '#{url(bunch)}'`
218
+ `open '#{_url}'`
219
219
  end
220
220
  end
221
221
  end
@@ -158,7 +158,7 @@ class BunchFinder
158
158
  attr_accessor :config_dir
159
159
 
160
160
  def initialize
161
- config_dir = `defaults read com.brettterpstra.bunch configDir`.strip
161
+ config_dir = `osascript -e 'tell app "#{TARGET_APP}" to get preference "Folder"'`.strip
162
162
  config_dir = File.expand_path(config_dir)
163
163
  if File.directory?(config_dir)
164
164
  @config_dir = config_dir
@@ -167,6 +167,15 @@ class BunchFinder
167
167
  end
168
168
  end
169
169
 
170
+ def bunches_to_items
171
+ items = []
172
+ `osascript -e 'tell app "#{TARGET_APP}" to list bunches'`.strip.split(/,/).each do |b|
173
+ filename = b.strip
174
+ items << MenuItem.new(filename, filename, filename)
175
+ end
176
+ items
177
+ end
178
+
170
179
  def files_to_items(dir, pattern)
171
180
  Dir.chdir(dir)
172
181
  items = []
@@ -180,12 +189,12 @@ class BunchFinder
180
189
  end
181
190
 
182
191
  def choose_bunch
183
- items = files_to_items(@config_dir, '*.bunch')
184
- items.map! do |item|
185
- item.title = File.basename(item.title, '.bunch')
186
- item.value = File.basename(item.title, '.bunch')
187
- item
188
- end
192
+ items = bunches_to_items
193
+ # items.map! do |item|
194
+ # item.title = File.basename(item.title, '.bunch')
195
+ # item.value = File.basename(item.title, '.bunch')
196
+ # item
197
+ # end
189
198
  menu = Menu.new(items)
190
199
  menu.choose('Select a Bunch')
191
200
  end
data/lib/bunch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BunchCLI
2
- VERSION = "1.1.9.pre"
2
+ VERSION = "1.1.10.pre"
3
3
  end
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.9.pre
4
+ version: 1.1.10.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-04-14 00:00:00.000000000 Z
11
+ date: 2021-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: