Skip to content

Instantly share code, notes, and snippets.

@miguelSantirso
Last active August 29, 2015 13:58
Show Gist options
  • Save miguelSantirso/10160597 to your computer and use it in GitHub Desktop.
Save miguelSantirso/10160597 to your computer and use it in GitHub Desktop.
Open file with default app in Ruby
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