bunchcli 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/bin/bunch +66 -0
- data/bunchcli.gemspec +26 -0
- data/lib/bunch.rb +7 -0
- data/lib/bunch/bunchCLI.rb +148 -0
- data/lib/bunch/version.rb +3 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '064668e5dae28ec08fe4a939dc270e9b1880116f68f8ad39fc3c2252cd7609fa'
|
4
|
+
data.tar.gz: be7be6b0cf5404ae193aec36d50b4efa4b6672b03be4e875f60cd89fcf3a07b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59abf612ddfe2eff6f5b54bf7952e08f67cad5bc7c2ec06ca9eb6d15aa097798c6bfaf6686292041fba6dd4fd34e3dc013ef3ffdff60c271a85b0fa99b64b144
|
7
|
+
data.tar.gz: e888ed65aef4791420808cc5220f275c9e3c9c618ba931d273f4b118f3ffdcecb978b641e298ba0d18024758977ba3e883095daca71859af25e381291f903ce9
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Brett Terpstra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Bunch
|
2
|
+
|
3
|
+
A CLI for [Bunch.app](https://brettterpstra.com/projects/bunch).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install bunch
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ bunch -h
|
12
|
+
CLI for Bunch.app
|
13
|
+
-h, --help Display this screen
|
14
|
+
-f, --force-refresh Force refresh cached preferences
|
15
|
+
-l, --list List available Bunches
|
16
|
+
-o, --open Open Bunch ignoring "Toggle Bunches" preference
|
17
|
+
-c, --close Close Bunch ignoring "Toggle Bunches" preference
|
18
|
+
-t, --toggle Toggle Bunch ignoring "Toggle Bunches" preference
|
19
|
+
-s, --show BUNCH Show contents of Bunch
|
20
|
+
--show-config Display configuration values
|
21
|
+
|
22
|
+
Usage: `bunch [options] BUNCH_NAME|PATH_TO_FILE`
|
23
|
+
|
24
|
+
Bunch names are case insensitive and will execute first match
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/bunch
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'bunch'
|
5
|
+
|
6
|
+
def help
|
7
|
+
puts "\nUsage: #{File.basename(__FILE__)} [options] BUNCH_NAME|PATH_TO_FILE"
|
8
|
+
puts "\nBunch names are case insensitive and will execute first match"
|
9
|
+
end
|
10
|
+
|
11
|
+
bunch = Bunch.new
|
12
|
+
|
13
|
+
optparse = OptionParser.new do |opts|
|
14
|
+
opts.banner = 'CLI for Bunch.app'
|
15
|
+
|
16
|
+
opts.on('-h', '--help', 'Display this screen') do |_opt|
|
17
|
+
puts opts
|
18
|
+
help
|
19
|
+
Process.exit 0
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on('-f', '--force-refresh', 'Force refresh cached preferences') do |opt|
|
23
|
+
bunch.update_cache
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-l', '--list', 'List available Bunches') do |_opt|
|
27
|
+
bunch.list_bunches
|
28
|
+
Process.exit 0
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-o', '--open', 'Open Bunch ignoring "Toggle Bunches" preference') do |_opt|
|
32
|
+
bunch.url_method = 'open'
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on('-c', '--close', 'Close Bunch ignoring "Toggle Bunches" preference') do |_opt|
|
36
|
+
bunch.url_method = 'close'
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-t', '--toggle', 'Toggle Bunch ignoring "Toggle Bunches" preference') do |_opt|
|
40
|
+
bunch.url_method = 'toggle'
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('-s', '--show BUNCH', 'Show contents of Bunch') do |opt|
|
44
|
+
bunch.show(opt)
|
45
|
+
Process.exit 0
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on('--show-config', 'Display configuration values') do |opt|
|
49
|
+
bunch.show_config
|
50
|
+
Process.exit 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
optparse.parse!
|
55
|
+
|
56
|
+
unless ARGV.length > 0
|
57
|
+
if STDIN.stat.size > 0
|
58
|
+
bunch.url_method = 'raw'
|
59
|
+
bunch.open(CGI.escape(STDIN.read))
|
60
|
+
else
|
61
|
+
puts "CLI for Bunches.app"
|
62
|
+
help
|
63
|
+
end
|
64
|
+
else
|
65
|
+
ARGV.map { |arg| bunch.open(arg) }
|
66
|
+
end
|
data/bunchcli.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/bunch/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "bunchcli"
|
5
|
+
spec.version = BunchCLI::VERSION
|
6
|
+
spec.authors = ["Brett Terpstra"]
|
7
|
+
spec.email = ["me@brettterpstra.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A CLI for use with Bunch.app (macOS)}
|
10
|
+
spec.homepage = "https://brettterpstra.com/projects/bunch"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/ttscoff/bunchCLI"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/ttscoff/bunchCLI/blob/master/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "bin"
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
data/lib/bunch.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
class Bunch
|
2
|
+
attr_writer :url_method
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@bunch_dir = nil
|
6
|
+
@url_method = nil
|
7
|
+
@bunches = nil
|
8
|
+
get_cache
|
9
|
+
end
|
10
|
+
|
11
|
+
def update_cache
|
12
|
+
@bunch_dir = nil
|
13
|
+
@url_method = nil
|
14
|
+
@bunches = nil
|
15
|
+
target = File.expand_path(CACHE_FILE)
|
16
|
+
settings = {
|
17
|
+
'bunchDir' => bunch_dir,
|
18
|
+
'method' => url_method,
|
19
|
+
'bunches' => bunches,
|
20
|
+
'updated' => Time.now.strftime('%s').to_i
|
21
|
+
}
|
22
|
+
File.open(target,'w') do |f|
|
23
|
+
f.puts YAML.dump(settings)
|
24
|
+
end
|
25
|
+
return settings
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_cache
|
29
|
+
target = File.expand_path(CACHE_FILE)
|
30
|
+
if File.exists?(target)
|
31
|
+
settings = YAML.load(IO.read(target))
|
32
|
+
now = Time.now.strftime('%s').to_i
|
33
|
+
if now - settings['updated'].to_i > CACHE_TIME
|
34
|
+
settings = update_cache
|
35
|
+
end
|
36
|
+
else
|
37
|
+
settings = update_cache
|
38
|
+
end
|
39
|
+
@bunch_dir = settings['bunchDir'] || bunch_dir
|
40
|
+
@url_method = settings['method'] || url_method
|
41
|
+
@bunches = settings['bunches'] || generate_bunch_list
|
42
|
+
end
|
43
|
+
|
44
|
+
# items.push({title: 0})
|
45
|
+
def generate_bunch_list
|
46
|
+
items = []
|
47
|
+
Dir.glob(File.join(bunch_dir, '*.bunch')).each do |f|
|
48
|
+
items.push(
|
49
|
+
path: f,
|
50
|
+
title: File.basename(f, '.bunch')
|
51
|
+
)
|
52
|
+
end
|
53
|
+
items
|
54
|
+
end
|
55
|
+
|
56
|
+
def bunch_dir
|
57
|
+
@bunch_dir ||= begin
|
58
|
+
dir = `/usr/bin/defaults read #{ENV['HOME']}/Library/Preferences/com.brettterpstra.Bunch.plist configDir`.strip
|
59
|
+
File.expand_path(dir)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def url_method
|
64
|
+
@url_method ||= `/usr/bin/defaults read #{ENV['HOME']}/Library/Preferences/com.brettterpstra.Bunch.plist toggleBunches`.strip == '1' ? 'toggle' : 'open'
|
65
|
+
end
|
66
|
+
|
67
|
+
def bunches
|
68
|
+
@bunches ||= generate_bunch_list
|
69
|
+
end
|
70
|
+
|
71
|
+
def url(bunch)
|
72
|
+
if url_method == 'file'
|
73
|
+
%(x-bunch://raw?file=#{bunch})
|
74
|
+
elsif url_method == 'raw'
|
75
|
+
%(x-bunch://raw?txt=#{bunch})
|
76
|
+
else
|
77
|
+
%(x-bunch://#{url_method}?bunch=#{bunch[:title]})
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def bunch_list
|
82
|
+
list = []
|
83
|
+
bunches.each { |bunch| list.push(bunch[:title]) }
|
84
|
+
list
|
85
|
+
end
|
86
|
+
|
87
|
+
def list_bunches
|
88
|
+
$stdout.puts bunch_list.join("\n")
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_bunch(str)
|
92
|
+
found_bunch = false
|
93
|
+
|
94
|
+
bunches.each do |bunch|
|
95
|
+
if bunch[:title].downcase =~ /.*?#{str}.*?/i
|
96
|
+
found_bunch = bunch
|
97
|
+
break
|
98
|
+
end
|
99
|
+
end
|
100
|
+
found_bunch
|
101
|
+
end
|
102
|
+
|
103
|
+
def human_action
|
104
|
+
(url_method.gsub(/e$/, '') + 'ing').capitalize
|
105
|
+
end
|
106
|
+
|
107
|
+
def open(str)
|
108
|
+
# get front app
|
109
|
+
front_app = %x{osascript -e 'tell application "System Events" to return name of first application process whose frontmost is true'}.strip
|
110
|
+
if @url_method == 'raw'
|
111
|
+
warn 'Running raw string'
|
112
|
+
`open '#{url(str)}'`
|
113
|
+
else
|
114
|
+
bunch = find_bunch(str)
|
115
|
+
unless bunch
|
116
|
+
if File.exists?(str)
|
117
|
+
@url_method = 'file'
|
118
|
+
warn "Opening file"
|
119
|
+
`open '#{url(str)}'`
|
120
|
+
else
|
121
|
+
warn 'No matching Bunch found'
|
122
|
+
Process.exit 1
|
123
|
+
end
|
124
|
+
else
|
125
|
+
warn "#{human_action} #{bunch[:title]}"
|
126
|
+
|
127
|
+
`open "#{url(bunch)}"`
|
128
|
+
end
|
129
|
+
end
|
130
|
+
# attempt to restore front app
|
131
|
+
%x{osascript -e 'delay 2' -e 'tell application "#{front_app}" to activate'}
|
132
|
+
end
|
133
|
+
|
134
|
+
def show(str)
|
135
|
+
bunch = find_bunch(str)
|
136
|
+
output = `cat "#{bunch[:path]}"`.strip
|
137
|
+
puts output
|
138
|
+
end
|
139
|
+
|
140
|
+
def show_config
|
141
|
+
puts "Bunches Folder: #{bunch_dir}"
|
142
|
+
puts "Default URL Method: #{url_method}"
|
143
|
+
puts "Cached Bunches"
|
144
|
+
bunches.each {|b|
|
145
|
+
puts " - #{b[:title]}"
|
146
|
+
}
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunchcli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Terpstra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- me@brettterpstra.com
|
16
|
+
executables:
|
17
|
+
- bunch
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/bunch
|
28
|
+
- bunchcli.gemspec
|
29
|
+
- lib/bunch.rb
|
30
|
+
- lib/bunch/bunchCLI.rb
|
31
|
+
- lib/bunch/version.rb
|
32
|
+
homepage: https://brettterpstra.com/projects/bunch
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://brettterpstra.com/projects/bunch
|
37
|
+
source_code_uri: https://github.com/ttscoff/bunchCLI
|
38
|
+
changelog_uri: https://github.com/ttscoff/bunchCLI/blob/master/CHANGELOG.md
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.1.4
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A CLI for use with Bunch.app (macOS)
|
58
|
+
test_files: []
|