Last active
August 29, 2015 13:58
-
-
Save miguelSantirso/10160597 to your computer and use it in GitHub Desktop.
Open file with default app in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def open_with_default_app path_to_file | |
if is_windows? | |
%x{start /MIN #{path_to_file}} | |
elsif is_mac? | |
%x{open -g \"#{path_to_file}\"} | |
elsif is_linux? | |
%x{xdg-open \"#{path_to_file}\"} | |
else | |
puts "Platform not supported: #{RUBY_PLATFORM}" | |
end | |
end | |
def is_mac? | |
RUBY_PLATFORM.downcase.include?("darwin") | |
end | |
def is_windows? | |
RUBY_PLATFORM.downcase.include?("mswin") || RUBY_PLATFORM.downcase.include?("mingw") | |
end | |
def is_linux? | |
RUBY_PLATFORM.downcase.include?("linux") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment