Permalink
Browse files

Detach!

  • Loading branch information...
1 parent 4746e52 commit 1dbd4440acaa328a191119d05f6ae2480b386fca @lasersox lasersox committed Sep 24, 2010
Showing with 16 additions and 10 deletions.
  1. +16 −10 rmate
View
26 rmate
@@ -86,18 +86,15 @@ OptionParser.new do |o|
end
o.parse!
end
-
host, port = '127.0.0.1', 52698
if conn = ENV['SSH_CONNECTION']
host = conn.split(' ').first
end
-socket = TCPSocket.new(host, port)
-server_info = socket.readline.chomp
-$stderr.puts "Connect: ‘#{server_info}" if $verbose
-
+## Parse arguments.
+cmds = []
ARGV.each do |path|
abort "File #{path} is not writable! Use -f/--force to open anyway." unless force or File.writable? path
$stderr.puts "File #{path} is not writable. Opening anyway." if not File.writable? path and $verbose
@@ -109,13 +106,22 @@ ARGV.each do |path|
cmd['token'] = path
cmd.read_file(path) if File.exist? path
cmd['data'] = "0" unless File.exist? path
- cmd.send(socket)
+ cmds << cmd
end
-socket.puts "."
+# Now go detach and connect to the server.
+pid = fork do
+ socket = TCPSocket.new(host, port)
+ server_info = socket.readline.chomp
+ $stderr.puts "Connect: ‘#{server_info}" if $verbose
+
+ cmds.each { |cmd| cmd.send(socket) }
-handle_cmd(socket) while !socket.eof?
+ socket.puts "."
+ handle_cmd(socket) while !socket.eof?
+ socket.close
+ $stderr.puts "Done" if $verbose
+end
-socket.close
+Process.detach(pid)
-$stderr.puts "Done" if $verbose

0 comments on commit 1dbd444

Please sign in to comment.