Skip to content

Commit

Permalink
use xdg-open on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Jun 20, 2010
1 parent 5385fe7 commit ff13762
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
15 changes: 5 additions & 10 deletions bin/bcat
Expand Up @@ -33,9 +33,10 @@ ARGV.push '-' if ARGV.empty?

require 'bcat'
notice "loaded bcat v#{Bcat::VERSION}"
command = ENV['BCAT_COMMAND'] || 'open $BCAT_ARGS "$BCAT_URL"'

include Bcat::Browser
notice "env BCAT_APPLICATION=#{ENV['BCAT_APPLICATION'].inspect}"
notice "env BCAT_COMMAND=#{command.inspect}"
notice "env BCAT_COMMAND=#{browser_command.inspect}"

reader =
if File.basename($0) =~ /tee$/
Expand All @@ -49,14 +50,8 @@ pid = nil
begin
bcat = Bcat.new(reader, options)
bcat.serve! do |sock|
pid =
fork do
(reader.fds + [sock, $stdin, $stdout]).uniq.each { |fd| fd.close }
ENV['BCAT_URL'] = "http://#{bcat[:Host]}:#{bcat[:Port]}/#{File.basename(Dir.pwd)}"
ENV['BCAT_ARGS'] = "-a '#{ENV['BCAT_APPLICATION']}'" if !ENV['BCAT_APPLICATION'].to_s.empty?
notice "exec #{command.inspect}"
exec "/bin/sh -c \"#{command}\""
end
url = "http://#{bcat[:Host]}:#{bcat[:Port]}/#{File.basename(Dir.pwd)}"
pid = browser(url)
end
rescue Interrupt
notice "interrupt"
Expand Down
1 change: 1 addition & 0 deletions lib/bcat.rb
@@ -1,6 +1,7 @@
require 'rack'
require 'bcat/reader'
require 'bcat/kidgloves'
require 'bcat/browser'

class Bcat
VERSION = '0.0.1'
Expand Down
24 changes: 24 additions & 0 deletions lib/bcat/browser.rb
@@ -0,0 +1,24 @@
class Bcat
module Browser
def browser(url, application=ENV['BCAT_APPLICATION'])
command = browser_command
fork do
[$stdin, $stdout].each { |fd| fd.close }
ENV['BCAT_ARGS'] = "-a '#{application}'" if !application.to_s.empty?
ENV['BCAT_URL'] = url
ENV['BCAT_COMMAND'] = command
exec "/bin/sh -c \"#{command.gsub(/"/, '\"')}\""
end
end

def browser_command
return ENV['BCAT_COMMAND'] if !ENV['BCAT_COMMAND'].to_s.empty?

case `uname`
when /Linux/ ; 'xdg-open $BCAT_ARGS "$BCAT_URL"'
when /Darwin/ ; 'open $BCAT_ARGS "$BCAT_URL"'
else ; 'firefox "$BCAT_URL"'
end
end
end
end

0 comments on commit ff13762

Please sign in to comment.