Module: CommandKit::OpenApp
Overview
Allows opening a file or a URI with the system's preferred application for that file type or URI scheme.
Examples
open_app_for "movie.avi"
open_app_for "https://github.com/postmodern/command_kit.rb#readme"
Instance Attribute Summary
Attributes included from Env::Path
Attributes included from Env
Attributes included from OS
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ Object
Initializes the command and determines which open command to use.
-
#open_app_for(file_or_uri) ⇒ Boolean?
Opens a file or URI using the system's preferred application for that file type or URI scheme.
Methods included from Env::Path
#command_installed?, #find_command
Methods included from OS
#bsd?, #freebsd?, #linux?, #macos?, #netbsd?, #openbsd?, #unix?, #windows?
Methods included from CommandKit::OS::ModuleMethods
Instance Method Details
#initialize(**kwargs) ⇒ Object
Initializes the command and determines which open command to use.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/command_kit/open_app.rb', line 30 def initialize(**kwargs) super(**kwargs) @open_command = if macos? 'open' elsif linux? || bsd? if command_installed?('xdg-open') 'xdg-open' end elsif windows? if command_installed?('invoke-item') 'invoke-item' else 'start' end end end |
#open_app_for(file_or_uri) ⇒ Boolean?
Opens a file or URI using the system's preferred application for that file type or URI scheme.
65 66 67 68 69 |
# File 'lib/command_kit/open_app.rb', line 65 def open_app_for(file_or_uri) if @open_command system(@open_command,file_or_uri.to_s) end end |