Skip to content

Commit

Permalink
Using xdg-open for Linux.
Browse files Browse the repository at this point in the history
xdg-open uses the default application to open a given
file based on mime type.
  • Loading branch information
PotHix committed Feb 9, 2013
1 parent 273f8cd commit 75d42e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/kitabu/cli.rb
Expand Up @@ -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])
Expand Down
9 changes: 7 additions & 2 deletions lib/kitabu/exporter.rb
Expand Up @@ -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(
Expand Down

0 comments on commit 75d42e6

Please sign in to comment.