Sha256: 83c1bac25076d772ecb85bb9c4f8ead3b4075e6f25a459d921be23d6bdd0776f

Contents?: true

Size: 821 Bytes

Versions: 30

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

module TTY
  # Additional app-bundle-specific routines for TTY::Which
  module Which
    def app_bundle(cmd)
      app = cmd.sub(/(\.app)?$/, '.app')
      command = cmd.dup
      command.sub!(/\.app$/, '')
      app_dirs = %w[/Applications /Applications/Setapp ~/Applications]
      return command if ::File.exist?(app)

      return command if app_dirs.any? { |dir| ::File.exist?(::File.join(dir, app)) }

      false
    end
    module_function :app_bundle

    def bundle_id?(id)
      id =~ /^\w+(\.\w+){2,}/ ? true : false
    end
    module_function :bundle_id?

    def app?(cmd)
      if file_with_path?(cmd)
        return cmd if app_bundle(cmd)
      else
        app = app_bundle(cmd)
        return app if app
      end

      false
    end
    module_function :app?
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
snibbets-2.0.40 lib/snibbets/which.rb
snibbets-2.0.39 lib/snibbets/which.rb
snibbets-2.0.38 lib/snibbets/which.rb
snibbets-2.0.37 lib/snibbets/which.rb
snibbets-2.0.36 lib/snibbets/which.rb
snibbets-2.0.35 lib/snibbets/which.rb
snibbets-2.0.34 lib/snibbets/which.rb
snibbets-2.0.33 lib/snibbets/which.rb
snibbets-2.0.32 lib/snibbets/which.rb
snibbets-2.0.31 lib/snibbets/which.rb
snibbets-2.0.30 lib/snibbets/which.rb
snibbets-2.0.29 lib/snibbets/which.rb
snibbets-2.0.28 lib/snibbets/which.rb
snibbets-2.0.27 lib/snibbets/which.rb
snibbets-2.0.26 lib/snibbets/which.rb
snibbets-2.0.25 lib/snibbets/which.rb
snibbets-2.0.24 lib/snibbets/which.rb
snibbets-2.0.23 lib/snibbets/which.rb
snibbets-2.0.22 lib/snibbets/which.rb
snibbets-2.0.21 lib/snibbets/which.rb