Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding -w/--wait flag to let rmate block while the user edits the fil…

…e. This is to support GIT_EDITOR and other such use-cases.
  • Loading branch information...
commit fd93f962ea3146b1f5add073b41e87e8a31ff553 1 parent e35b920
AJ Ross lasersox authored
Showing with 24 additions and 13 deletions.
  1. +24 −13 rmate
37 rmate
View
@@ -73,8 +73,22 @@ def handle_cmd(socket)
end
end
+def connect_and_handle_cmds(host, port, cmds)
+ socket = TCPSocket.new(host, port)
+ server_info = socket.readline.chomp
+ $stderr.puts "Connect: ‘#{server_info}" if $verbose
+
+ cmds.each { |cmd| cmd.send(socket) }
+
+ socket.puts "."
+ handle_cmd(socket) while !socket.eof?
+ socket.close
+ $stderr.puts "Done" if $verbose
+end
+
## MAIN
+wait = false
$verbose = false
force = false
OptionParser.new do |o|
@@ -84,6 +98,9 @@ OptionParser.new do |o|
o.on('-v', '--verbose', 'Verbose logging messages.') do |v|
$verbose = v
end
+ o.on('-w', '--wait', 'Wait for file to be closed by TextMate.') do |w|
+ wait = w
+ end
o.parse!
end
@@ -109,19 +126,13 @@ ARGV.each do |path|
cmds << cmd
end
-# 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) }
-
- socket.puts "."
- handle_cmd(socket) while !socket.eof?
- socket.close
- $stderr.puts "Done" if $verbose
+unless wait
+ pid = fork do
+ connect_and_handle_cmds(host, port, cmds)
+ end
+ Process.detach(pid)
+else
+ connect_and_handle_cmds(host, port, cmds)
end
-Process.detach(pid)
Please sign in to comment.
Something went wrong with that request. Please try again.