bunchcli 1.1.0 → 1.1.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: 010c20799d4e9e35409737ee3dfd5e3a755096ff212eb9a02787dfcee16dc5e2
4
- data.tar.gz: daccb516131e6816f4ea5cd153e14df691e3089600e77114e1755cf502efe131
3
+ metadata.gz: 85429d178706578f82263c19457bf79b369efee746ac17172e1b065c6fb4a1eb
4
+ data.tar.gz: 12dc65b8c0c8c3b86c3ef050c30e4aa756b8596ca0388d4c4c89b1bdf0db3beb
5
5
  SHA512:
6
- metadata.gz: b9f94711eadea1d3cf6cd3ebef2244663cc793b1dc3bd121ac2bb1409431c24215d03b172db13d76966143529c99578bfce000bebbba89dbbf16410d1653ab93
7
- data.tar.gz: 2923722c6988c146be4eaa19b20b732413eb95fad52c890a0bd47165e50a61e576042d4934d376a6f5ed992723f5d843ee645b3eaa7eb10cdb677628f996ce99
6
+ metadata.gz: b38da1ccef956f64112c4aa70f2f195b9200f134cf7415d7ed5651e93719acb2d289462b171d61ff7573566467b6804b0039f27ed681fbaf56e758c0428b713b
7
+ data.tar.gz: 57de9a2b54ad9f6de4bc9328c1badd2342e1b7c8ac6683d3aa4ef4a098d9fcdd03f6d6d01bf1b99b49faad27c4b675793256bbcf22c864d901a2bf6f57e64d07
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ### 1.1.5
2
+
3
+ - Add some color to the interactive URL generator
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
+
13
+ ### 1.1.2
14
+
15
+ - Allow app name in x-success if bundle id can't be found
16
+
17
+ ### 1.1
18
+
19
+ - Add interactive URL builder
20
+ - Snippet handling
21
+
1
22
  ### 1.0
2
23
 
3
24
  - Initial release
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
+ gem 'term-colorizer'
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bunchcli (1.0.0)
4
+ bunchcli (1.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  rake (12.3.3)
10
+ term-colorizer (0.2.1)
10
11
 
11
12
  PLATFORMS
12
13
  x86_64-darwin-19
@@ -14,6 +15,7 @@ PLATFORMS
14
15
  DEPENDENCIES
15
16
  bunchcli!
16
17
  rake (~> 12.0)
18
+ term-colorizer
17
19
 
18
20
  BUNDLED WITH
19
21
  2.2.4
data/README.md CHANGED
@@ -10,14 +10,21 @@ A CLI for [Bunch.app](https://brettterpstra.com/projects/bunch).
10
10
 
11
11
  $ bunch -h
12
12
  CLI for Bunch.app
13
- -h, --help Display this screen
14
- -f, --force-refresh Force refresh cached preferences
15
13
  -l, --list List available Bunches
14
+ -s, --show BUNCH Show contents of Bunch
16
15
  -o, --open Open Bunch ignoring "Toggle Bunches" preference
17
16
  -c, --close Close Bunch ignoring "Toggle Bunches" preference
18
17
  -t, --toggle Toggle Bunch ignoring "Toggle Bunches" preference
19
- -s, --show BUNCH Show contents of Bunch
18
+ --snippet Load as snippet
19
+ --fragment=FRAGMENT Run a specific section
20
+ --vars=VARS Variables to pass to a snippet, comma-separated
21
+ --pref Set a preference. Run without argument to list available preferences.
22
+ -u, --url Output URL instead of opening
23
+ -i, --interactive Interactively generate a Bunch url
20
24
  --show-config Display configuration values
25
+ -f, --force-refresh Force refresh cached preferences
26
+ -h, --help Display this screen
27
+ -v, --version Display Bunch version
21
28
 
22
29
  Usage: `bunch [options] BUNCH_NAME|PATH_TO_FILE`
23
30
 
data/bin/bunch CHANGED
@@ -6,12 +6,17 @@ require 'bunch'
6
6
  def help
7
7
  puts "\nUsage: #{File.basename(__FILE__)} [options] BUNCH_NAME|PATH_TO_FILE"
8
8
  puts "\nBunch names are case insensitive and will execute first match"
9
+ puts "Use 'bunch -h' to display options"
10
+ end
11
+
12
+ def version
13
+ puts "Bunch CLI v#{BunchCLI::VERSION}"
9
14
  end
10
15
 
11
16
  bunch = Bunch.new
12
17
 
13
18
  optparse = OptionParser.new do |opts|
14
- opts.banner = 'CLI for Bunch.app'
19
+ opts.banner = "CLI for Bunch.app v#{BunchCLI::VERSION}"
15
20
 
16
21
  opts.on('-l', '--list', 'List available Bunches') do |_opt|
17
22
  bunch.list_bunches
@@ -47,6 +52,10 @@ optparse = OptionParser.new do |opts|
47
52
  bunch.variables = opt
48
53
  end
49
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
+
50
59
  opts.on('-u', '--url', 'Output URL instead of opening') do |_opt|
51
60
  bunch.show_url = true
52
61
  end
@@ -56,11 +65,16 @@ optparse = OptionParser.new do |opts|
56
65
  Process.exit 0
57
66
  end
58
67
 
59
- opts.on('--show-config', 'Display configuration values') do |opt|
68
+ opts.on('--show-config', 'Display all configuration values') do |opt|
60
69
  bunch.show_config
61
70
  Process.exit 0
62
71
  end
63
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
+
64
78
  opts.on('-f', '--force-refresh', 'Force refresh cached preferences') do |opt|
65
79
  bunch.update_cache
66
80
  end
@@ -70,6 +84,11 @@ optparse = OptionParser.new do |opts|
70
84
  help
71
85
  Process.exit 0
72
86
  end
87
+
88
+ opts.on('-v', '--version', 'Display Bunch version') do |_opt|
89
+ version
90
+ Process.exit 0
91
+ end
73
92
  end
74
93
 
75
94
  optparse.parse!
@@ -78,6 +97,8 @@ unless ARGV.length > 0
78
97
  if STDIN.stat.size > 0
79
98
  bunch.url_method = 'raw'
80
99
  bunch.open(CGI.escape(STDIN.read))
100
+ elsif bunch.url_method == 'setPref'
101
+ bunch.list_preferences
81
102
  else
82
103
  puts "CLI for Bunches.app"
83
104
  help
data/lib/bunch.rb CHANGED
@@ -5,4 +5,5 @@ require "bunch/version"
5
5
  require 'yaml'
6
6
  require 'cgi'
7
7
  require 'bunch/url_generator'
8
+ require 'term-colorizer'
8
9
  require 'bunch/bunchCLI'
@@ -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
@@ -17,12 +17,13 @@ module Util
17
17
  shortname = app.sub(/\.app$/, '')
18
18
  apps = `mdfind -onlyin /Applications -onlyin /Applications/Setapp -onlyin /Applications/Utilities -onlyin ~/Applications -onlyin /Developer/Applications 'kMDItemKind==Application'`
19
19
 
20
- app = apps.split(/\n/).select! { |line| line.chomp =~ /#{shortname}\.app$/ }[0]
20
+ foundapp = apps.split(/\n/).select! { |line| line.chomp =~ /#{shortname}\.app$/i }[0]
21
21
 
22
- if app
23
- bid = `mdls -name kMDItemCFBundleIdentifier -r "#{app}"`.chomp
22
+ if foundapp
23
+ bid = `mdls -name kMDItemCFBundleIdentifier -r "#{foundapp}"`.chomp
24
24
  else
25
- warn "Could not locate bundle id for #{shortname}"
25
+ # warn "Could not locate bundle id for #{shortname}, using provided app name"
26
+ bid = app
26
27
  end
27
28
  bid
28
29
  end
@@ -48,7 +49,8 @@ module Prompt
48
49
  def get_line(query = '->')
49
50
  stty_save = `stty -g`.chomp
50
51
  begin
51
- line = Readline.readline("#{query}: ", true)
52
+ print query.bright_green
53
+ line = Readline.readline(": ", true)
52
54
  rescue Interrupt
53
55
  system('stty', stty_save) # Restore
54
56
  exit
@@ -59,7 +61,7 @@ module Prompt
59
61
  def get_text(query = 'Enter text, ^d to end')
60
62
  stty_save = `stty -g`.chomp
61
63
  lines = []
62
- puts query
64
+ puts query.bright_green
63
65
  begin
64
66
  while (line = Readline.readline)
65
67
  lines << line
@@ -101,15 +103,15 @@ class Menu
101
103
  def choose(query = 'Select an item')
102
104
  throw 'No items initialized' if @items.nil?
103
105
  STDERR.puts
104
- STDERR.puts "┌#{("─" * 74)}┐"
106
+ STDERR.puts "┌#{("─" * 74)}┐".yellow
105
107
  intpad = Math::log10(@items.length).to_i + 1
106
108
  @items.each_with_index do |item, idx|
107
109
  idxstr = "%#{intpad}d" % (idx + 1)
108
110
  line = "#{idxstr}: #{item.title}"
109
111
  pad = 74 - line.length
110
- STDERR.puts "│#{line}#{" " * pad}│"
112
+ STDERR.puts "│".yellow + "#{line}#{" " * pad}".bright_white + "│".yellow
111
113
  end
112
- STDERR.puts "└┤ #{query} ├#{"─" * (70 - query.length)}┘"
114
+ STDERR.puts "└┤".yellow + " #{query} ".bright_green + "├#{"─" * (70 - query.length)}┘".yellow
113
115
  sel = choose_number("> ", @items.length)
114
116
  sel ? @items[sel.to_i - 1] : nil
115
117
  end
data/lib/bunch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BunchCLI
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.5"
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.0
4
+ version: 1.1.5
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-24 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: