#!/usr/bin/env ruby require 'optparse' require 'webrick' options = {} OptionParser.new do |opts| opts.banner = "breakneck: a quick way to serve static html sites immediately" opts.on("--port [PORT]", "Start on a different port (default: 3333)") do |port| options[:port] = port.to_i end opts.on("--open", "Open in the default browser") do options[:open] = true end end.parse! options[:port] ||= 3333 options[:open] ||= false server = WEBrick::HTTPServer.new( :Port => options[:port], :DocumentRoot => Dir.pwd ) thread = Thread.new do server.start end if options[:open] host_string = "http://localhost:#{options[:port]}/" system("open #{host_string} || firefox #{host_string}") end trap("INT") do server.shutdown end thread.join