Sha256: 9fc8f7f37d11d3c146fe111f0ef7da1805568580e763530097bf65c8d0c39dc2
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
#!/usr/bin/env ruby gem 'trollop', '~> 1.16.2' require "trollop" require "text_tunnel/version" config = Trollop.options do version "text_tunneld #{TextTunnel::VERSION}" opt :editor, "Editor command e.g. /usr/local/bin/subl (otherwise will use ENV[\"EDITOR\"])", :type => :string opt :daemon, "Run as daemon in background" opt :port, "Port", :type => :int, :default => 1777 opt :log, "Log file location", :type => :string opt :pid, "PID file location", :type => :string end editor = config[:editor] || ENV["EDITOR"] Trollop.die "No --editor argument or EDITOR environment variable" unless editor require "text_tunnel/watched_file" require "text_tunnel/watched_file_repository" require "text_tunnel/server" File.umask(0077) Server.configure do |s| s.set :environment, "production" s.set :bind, "127.0.0.1" s.set :port, config[:port] # Nesting callback because Sinatra evaluates the first automatically, so to # get a callback usable by Server it has to be wrapped. s.set :editor_spawner do Proc.new do |local_path| # Ordinarily, string concatenation should not be used for the command # string to spawn. However, if editor and local path are passed as # separate variables spawn will fail if the editor command has options # as it will treat the options as part of the file path. pid = spawn "#{editor} #{local_path}" Process.detach(pid) end end s.set :watched_files, WatchedFileRepository.new s.enable :logging end if config[:daemon] Process.daemon(true) end if config[:log] STDERR.reopen(open(config[:log], "w+")) end if config[:pid] File.write(config[:pid], Process.pid.to_s) at_exit { File.delete(config[:pid]) } end Server.run!
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
text_tunnel-0.2.0 | bin/text_tunneld |
text_tunnel-0.1.1 | bin/text_tunneld |
text_tunnel-0.1.0 | bin/text_tunneld |