Module: TTY::Which

Defined in:
lib/snibbets/which.rb

Overview

Additional app-bundle-specific routines for TTY::Which

Class Method Summary collapse

Class Method Details

.app?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/snibbets/which.rb', line 24

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

.app_bundle(cmd) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/snibbets/which.rb', line 6

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

.bundle_id?(id) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/snibbets/which.rb', line 19

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