bunchcli 1.1.2 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50e2a9587c1e477ebfba689ac13604b9a10c18669ca8669d90e66b579167f515
4
- data.tar.gz: '099d0e718b8ef7d4a54257158a6ae4b8914309c4ab730aa9bcbb5458b10faf6a'
3
+ metadata.gz: 55bb9ba0a6f1c9e3b4ede2e6c204b1e9803d080a5ebde6753cabad044303a474
4
+ data.tar.gz: c11edb485d0285f6badc37d11a06414a04856dfa76d01b8509a2ec189f7d696d
5
5
  SHA512:
6
- metadata.gz: b0527a019699115059a9015ca482b240300cabd85c397b02592ded404b02e85c8cec71cc8e97782578469d3e706e15da855963c828ff4cf3b01e9c5988d373d8
7
- data.tar.gz: 250aec6aeadeadfd87f68f30c1fa8c70c43b46c1f23aac5efb963319756693f5b756eb7bd4f6cfc0c7bb946a782b40d203c3acd0f8f31daa97e4136711215629
6
+ metadata.gz: 2ef4e5aac1183b3eaac52647d34775f105ea2da48ddd5ea45ebeb223912f00ee1212215a9cff7caaf9cbd06e78b43cfeb1a0fe7e5b223f4f0109e1b8f3aeb520
7
+ data.tar.gz: f13720b801abfe22f0d5585eeb9b9cc08dab31befa38bbaa73a6e96d0ef13d68254a7f7a0ce32d819c741a1c281380e4f0e924b3197906636a583d0b5309be4b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 1.1.7
2
+
3
+ - Bugfix
4
+
5
+ ### 1.1.4
6
+
7
+ - Add `--show-config-key KEY` query for specific keys (dir, toggle, method)
8
+
9
+ ### 1.1.3
10
+
11
+ - Add --prefs option
12
+
1
13
  ### 1.1.2
2
14
 
3
15
  - Allow app name in x-success if bundle id can't be found
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bunchcli (1.1.1)
4
+ bunchcli (1.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -18,11 +18,13 @@ A CLI for [Bunch.app](https://brettterpstra.com/projects/bunch).
18
18
  --snippet Load as snippet
19
19
  --fragment=FRAGMENT Run a specific section
20
20
  --vars=VARS Variables to pass to a snippet, comma-separated
21
+ --pref Set a preference. Run without argument to list available preferences.
21
22
  -u, --url Output URL instead of opening
22
23
  -i, --interactive Interactively generate a Bunch url
23
24
  --show-config Display configuration values
24
25
  -f, --force-refresh Force refresh cached preferences
25
26
  -h, --help Display this screen
27
+ -v, --version Display Bunch version
26
28
 
27
29
  Usage: `bunch [options] BUNCH_NAME|PATH_TO_FILE`
28
30
 
data/bin/bunch CHANGED
@@ -52,6 +52,10 @@ optparse = OptionParser.new do |opts|
52
52
  bunch.variables = opt
53
53
  end
54
54
 
55
+ opts.on('--pref', 'Set a preference. Run without argument to list available preferences.') do |opt|
56
+ bunch.url_method = 'setPref'
57
+ end
58
+
55
59
  opts.on('-u', '--url', 'Output URL instead of opening') do |_opt|
56
60
  bunch.show_url = true
57
61
  end
@@ -61,11 +65,16 @@ optparse = OptionParser.new do |opts|
61
65
  Process.exit 0
62
66
  end
63
67
 
64
- opts.on('--show-config', 'Display configuration values') do |opt|
68
+ opts.on('--show-config', 'Display all configuration values') do |opt|
65
69
  bunch.show_config
66
70
  Process.exit 0
67
71
  end
68
72
 
73
+ opts.on('--show-config-key KEY', 'Display a config value [dir, toggle, method]') do |opt|
74
+ bunch.show_config(opt)
75
+ Process.exit 0
76
+ end
77
+
69
78
  opts.on('-f', '--force-refresh', 'Force refresh cached preferences') do |opt|
70
79
  bunch.update_cache
71
80
  end
@@ -88,6 +97,8 @@ unless ARGV.length > 0
88
97
  if STDIN.stat.size > 0
89
98
  bunch.url_method = 'raw'
90
99
  bunch.open(CGI.escape(STDIN.read))
100
+ elsif bunch.url_method == 'setPref'
101
+ bunch.list_preferences
91
102
  else
92
103
  puts "CLI for Bunches.app"
93
104
  help
@@ -13,6 +13,14 @@ class Bunch
13
13
  get_cache
14
14
  end
15
15
 
16
+ def launch_if_needed
17
+ pid = `ps ax | grep 'MacOS/Bunch'|grep -v grep`.strip
18
+ if pid == ""
19
+ `open -a Bunch`
20
+ sleep 2
21
+ end
22
+ end
23
+
16
24
  def update_cache
17
25
  @bunch_dir = nil
18
26
  @url_method = nil
@@ -93,6 +101,8 @@ class Bunch
93
101
  %(x-bunch://raw?txt=#{bunch}#{params})
94
102
  elsif url_method == 'snippet'
95
103
  %(x-bunch://snippet?file=#{bunch}#{params})
104
+ elsif url_method == 'setPref'
105
+ %(x-bunch://setPref?#{bunch})
96
106
  else
97
107
  %(x-bunch://#{url_method}?bunch=#{bunch[:title]}#{params})
98
108
  end
@@ -124,7 +134,20 @@ class Bunch
124
134
  (url_method.gsub(/e$/, '') + 'ing').capitalize
125
135
  end
126
136
 
137
+ def list_preferences
138
+ prefs =<<EOF
139
+ toggleBunches=[0,1] Allow Bunches to be both opened and closed
140
+ configDir=[path] Absolute path to Bunches folder
141
+ singleBunchMode=[0,1] Close open Bunch when opening new one
142
+ preserveOpenBunches=[0,1] Restore Open Bunches on Launch
143
+ debugLevel=[0-4] Set the logging level for the Bunch Log
144
+ EOF
145
+ puts prefs
146
+ end
147
+
148
+
127
149
  def open(str)
150
+ launch_if_needed
128
151
  # get front app
129
152
  front_app = %x{osascript -e 'tell application "System Events" to return name of first application process whose frontmost is true'}.strip
130
153
  bid = bundle_id(front_app)
@@ -149,6 +172,19 @@ class Bunch
149
172
  warn "Opening snippet"
150
173
  `open '#{_url}'`
151
174
  end
175
+ elsif @url_method == 'setPref'
176
+ if str =~ /^(\w+)=([^= ]+)$/
177
+ _url = url(str)
178
+ if @show_url
179
+ $stdout.puts _url
180
+ else
181
+ warn "Setting preference #{str}"
182
+ `open '#{_url}'`
183
+ end
184
+ else
185
+ warn "Invalid key=value pair"
186
+ Process.exit 1
187
+ end
152
188
  else
153
189
  bunch = find_bunch(str)
154
190
  unless bunch
@@ -183,12 +219,21 @@ class Bunch
183
219
  puts output
184
220
  end
185
221
 
186
- def show_config
187
- puts "Bunches Folder: #{bunch_dir}"
188
- puts "Default URL Method: #{url_method}"
189
- puts "Cached Bunches"
190
- bunches.each {|b|
191
- puts " - #{b[:title]}"
192
- }
222
+ def show_config(key=nil)
223
+ case key
224
+ when /(folder|dir)/
225
+ puts bunch_dir
226
+ when /toggle/
227
+ puts url_method == 'toggle' ? 'true' : 'false'
228
+ when /method/
229
+ puts url_method
230
+ else
231
+ puts "Bunches Folder: #{bunch_dir}"
232
+ puts "Default URL Method: #{url_method}"
233
+ puts "Cached Bunches"
234
+ bunches.each {|b|
235
+ puts " - #{b[:title]}"
236
+ }
237
+ end
193
238
  end
194
239
  end
data/lib/bunch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BunchCLI
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.7"
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.2
4
+ version: 1.1.7
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-01-30 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: