bunchcli 1.1.1 → 1.1.6
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 +4 -4
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +3 -1
- data/README.md +2 -0
- data/bin/bunch +12 -1
- data/lib/bunch.rb +1 -0
- data/lib/bunch/bunchCLI.rb +52 -7
- data/lib/bunch/url_generator.rb +5 -4
- data/lib/bunch/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2a8a77faa358820416820ef2bd81752c699bfdc5f4d94b634833b85b4f740c9f
         | 
| 4 | 
            +
              data.tar.gz: a32335c4354e2a0958192d670c8a7d348ca283a1b077489c79e0c694fcd94acb
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 067dd0a90cf0464744465b378540c7ee9271f5d8571b1ff5116588402c22800d3a85e4c0d3f4e3c5f8fa779f3004deecccc256fb4640b937b6d9723bb87c9a20
         | 
| 7 | 
            +
              data.tar.gz: 6782b96d641b539cb465645d7d881300ec88e0a40f894fb5a2a9ff964671863e51a3251135f9084856d4f9a8747192b633906f7d98bb69ca67cb25125c7977c8
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,24 @@ | |
| 1 | 
            +
            ### 1.1.6
         | 
| 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 | 
            +
             | 
| 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.lock
    CHANGED
    
    | @@ -1,12 +1,13 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                bunchcli (1.1. | 
| 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
    
    | @@ -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
         | 
    
        data/lib/bunch.rb
    CHANGED
    
    
    
        data/lib/bunch/bunchCLI.rb
    CHANGED
    
    | @@ -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 | 
            -
                 | 
| 188 | 
            -
                 | 
| 189 | 
            -
             | 
| 190 | 
            -
                 | 
| 191 | 
            -
                  puts  | 
| 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/url_generator.rb
    CHANGED
    
    | @@ -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 | 
            -
                 | 
| 20 | 
            +
                foundapp = apps.split(/\n/).select! { |line| line.chomp =~ /#{shortname}\.app$/i }[0]
         | 
| 21 21 |  | 
| 22 | 
            -
                if  | 
| 23 | 
            -
                  bid = `mdls -name kMDItemCFBundleIdentifier -r "#{ | 
| 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
         | 
    
        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.6
         | 
| 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-02-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description:
         | 
| 14 14 | 
             
            email:
         |