Permalink
Browse files

Using xdg-open for Linux.

xdg-open uses the default application to open a given
file based on mime type.
  • Loading branch information...
1 parent 273f8cd commit 75d42e6b1079cdfd58cadd79df588d8286324798 @PotHix PotHix committed Feb 9, 2013
Showing with 8 additions and 3 deletions.
  1. +1 −1 lib/kitabu/cli.rb
  2. +7 −2 lib/kitabu/exporter.rb
View
2 lib/kitabu/cli.rb
@@ -26,7 +26,7 @@ def new(path)
desc "export [OPTIONS]", "Export e-book"
method_option :only, :type => :string, :desc => "Can be one of: #{FORMATS.join(", ")}"
- method_option :open, :type => :boolean, :desc => "Automatically open PDF (Mac OS X only)"
+ method_option :open, :type => :boolean, :desc => "Automatically open PDF (Preview.app for Mac OS X and xdg-open for Linux)"
def export
if options[:only] && !FORMATS.include?(options[:only])
View
9 lib/kitabu/exporter.rb
@@ -37,9 +37,14 @@ def export!
color = :green
message = options[:auto] ? "exported!" : "** e-book has been exported"
- if options[:open] && export_pdf && RUBY_PLATFORM =~ /darwin/
+ if options[:open] && export_pdf
filepath = root_dir.join("output/#{File.basename(root_dir)}.pdf")
- IO.popen("open -a Preview.app '#{filepath}'").close
+
+ if RUBY_PLATFORM =~ /darwin/
+ IO.popen("open -a Preview.app '#{filepath}'").close
+ elsif RUBY_PLATFORM =~ /linux/
+ Process.detach(Process.spawn("xdg-open '#{filepath}'", :out => "/dev/null"))
+ end
end
Notifier.notify(

0 comments on commit 75d42e6

Please sign in to comment.