rmate 1.5.5 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.mdown +17 -1
- data/bin/rmate +166 -143
- data/lib/rmate.rb +211 -2
- data/rmate.gemspec +1 -2
- metadata +26 -42
- data/lib/rmate/version.rb +0 -4
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a35cd85520fd713589268e5dfd6ae96ce687e2b
|
4
|
+
data.tar.gz: 79522d8ddc974740ee10e97512f91c403014bd2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac30238d09636d8a2313b1484c2ea3a2fdd6e8fc2354d8310b96ddd13326e23811959d19d52aee061fc44d7d4c0df856675f3f32f4ab4e7ca7d8047c2863c62a
|
7
|
+
data.tar.gz: 876dc96fb47785af45fa3ac014eb6d5f142d43dbe518bca98efe68a06cf953b2309a36421f5015d6bc30749ce4edc885e3f58297dd0fe17e8c8d63c48bb26dd2
|
data/README.mdown
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
If you wish to activate TextMate from an ssh session you can do so by copying the `rmate` (ruby) script to the server you are logged into. The script will connect back to TextMate running on your Mac so you should setup an ssh tunnel (as your Mac is likely behind NAT):
|
4
4
|
|
5
|
-
ssh -R 52698:
|
5
|
+
ssh -R 52698:localhost:52698 user@example.org
|
6
6
|
|
7
7
|
# Install
|
8
8
|
|
9
|
+
## Rubygems
|
10
|
+
|
9
11
|
You can install `rmate` via `gem`:
|
10
12
|
|
11
13
|
gem install rmate
|
@@ -14,6 +16,17 @@ Updating to latest version can be done using:
|
|
14
16
|
|
15
17
|
gem update rmate
|
16
18
|
|
19
|
+
## Standalone
|
20
|
+
|
21
|
+
Installing into `~/bin` can be done using these two lines:
|
22
|
+
|
23
|
+
curl -Lo ~/bin/rmate https://raw.github.com/textmate/rmate/master/bin/rmate
|
24
|
+
chmod a+x ~/bin/rmate
|
25
|
+
|
26
|
+
If `~/bin` is not already in your `PATH` then you may want to add something like this to your shell startup file (e.g. `~/.profile`):
|
27
|
+
|
28
|
+
export PATH="$PATH:$HOME/bin"
|
29
|
+
|
17
30
|
# Usage
|
18
31
|
|
19
32
|
rmate [options] file
|
@@ -30,3 +43,6 @@ For more info see this [blog post about rmate](http://blog.macromates.com/2011/m
|
|
30
43
|
# Ports
|
31
44
|
|
32
45
|
- [Bash](https://github.com/aurora/rmate) by Harald Lapp
|
46
|
+
|
47
|
+
|
48
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/textmate/rmate/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
data/bin/rmate
CHANGED
@@ -9,183 +9,206 @@ require 'socket'
|
|
9
9
|
require 'tempfile'
|
10
10
|
require 'yaml'
|
11
11
|
require 'fileutils'
|
12
|
-
require 'rmate'
|
13
12
|
|
14
|
-
|
13
|
+
module Rmate
|
14
|
+
DATE = "2013-08-02"
|
15
|
+
VERSION = "1.5.6"
|
16
|
+
VERSION_STRING = "rmate version #{Rmate::VERSION} (#{Rmate::DATE})"
|
15
17
|
|
16
|
-
class Settings
|
17
|
-
|
18
|
+
class Settings
|
19
|
+
attr_accessor :host, :port, :wait, :force, :verbose, :lines, :names, :types
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
def initialize
|
22
|
+
@host, @port = 'localhost', 52698
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
@wait = false
|
25
|
+
@force = false
|
26
|
+
@verbose = false
|
27
|
+
@lines = []
|
28
|
+
@names = []
|
29
|
+
@types = []
|
28
30
|
|
29
|
-
|
31
|
+
read_disk_settings
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
@host = ENV['RMATE_HOST'].to_s if ENV.has_key? 'RMATE_HOST'
|
34
|
+
@port = ENV['RMATE_PORT'].to_i if ENV.has_key? 'RMATE_PORT'
|
33
35
|
|
34
|
-
|
36
|
+
parse_cli_options
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
+
@host = parse_ssh_connection if @host == 'auto'
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
def read_disk_settings
|
42
|
+
[ "/etc/rmate.rc", "~/.rmate.rc"].each do |current_file|
|
43
|
+
file = File.expand_path current_file
|
44
|
+
if File.exist? file
|
45
|
+
params = YAML::load(File.open(file))
|
46
|
+
@host = params["host"] unless params["host"].nil?
|
47
|
+
@port = params["port"] unless params["port"].nil?
|
48
|
+
end
|
46
49
|
end
|
47
50
|
end
|
48
|
-
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
52
|
+
def parse_cli_options
|
53
|
+
OptionParser.new do |o|
|
54
|
+
o.on( '--host=name', "Connect to host.", "Use 'auto' to detect the host from SSH.", "Defaults to #{@host}.") { |v| @host = v }
|
55
|
+
o.on('-p', '--port=#', Integer, "Port number to use for connection.", "Defaults to #{@port}.") { |v| @port = v }
|
56
|
+
o.on('-w', '--[no-]wait', 'Wait for file to be closed by TextMate.') { |v| @wait = v }
|
57
|
+
o.on('-l', '--line [NUMBER]', 'Place caret on line [NUMBER] after loading file.') { |v| @lines <<= v }
|
58
|
+
o.on('-m', '--name [NAME]', 'The display name shown in TextMate.') { |v| @names <<= v }
|
59
|
+
o.on('-t', '--type [TYPE]', 'Treat file as having [TYPE].') { |v| @types <<= v }
|
60
|
+
o.on('-f', '--force', 'Open even if the file is not writable.') { |v| @force = v }
|
61
|
+
o.on('-v', '--verbose', 'Verbose logging messages.') { |v| @verbose = v }
|
62
|
+
o.on_tail('-h', '--help', 'Show this message.') { puts o; exit }
|
63
|
+
o.on_tail( '--version', 'Show version.') { puts VERSION_STRING; exit }
|
64
|
+
o.parse!
|
65
|
+
end
|
63
66
|
end
|
64
|
-
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
def parse_ssh_connection
|
69
|
+
ENV['SSH_CONNECTION'].nil? ? 'localhost' : ENV['SSH_CONNECTION'].split(' ').first
|
70
|
+
end
|
68
71
|
end
|
69
|
-
end
|
70
72
|
|
71
|
-
class Command
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
def []=(name, value)
|
80
|
-
@variables[name] = value
|
81
|
-
end
|
82
|
-
|
83
|
-
def read_file(path)
|
84
|
-
@size = File.size(path)
|
85
|
-
@data = File.open(path, "rb") { |io| io.read(@size) }
|
86
|
-
end
|
87
|
-
|
88
|
-
def send(socket)
|
89
|
-
socket.puts @command
|
90
|
-
@variables.each_pair do |name, value|
|
91
|
-
value = 'yes' if value === true
|
92
|
-
socket.puts "#{name}: #{value}"
|
73
|
+
class Command
|
74
|
+
def initialize(name)
|
75
|
+
@command = name
|
76
|
+
@variables = {}
|
77
|
+
@data = nil
|
78
|
+
@size = nil
|
93
79
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
80
|
+
|
81
|
+
def []=(name, value)
|
82
|
+
@variables[name] = value
|
97
83
|
end
|
98
|
-
socket.puts
|
99
|
-
end
|
100
|
-
end
|
101
84
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
85
|
+
def read_file(path)
|
86
|
+
@size = File.size(path)
|
87
|
+
@data = File.open(path, "rb") { |io| io.read(@size) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_stdin
|
91
|
+
@data = $stdin.read
|
92
|
+
@size = @data.size
|
93
|
+
end
|
94
|
+
|
95
|
+
def send(socket)
|
96
|
+
socket.puts @command
|
97
|
+
@variables.each_pair do |name, value|
|
98
|
+
value = 'yes' if value === true
|
99
|
+
socket.puts "#{name}: #{value}"
|
100
|
+
end
|
101
|
+
if @data
|
102
|
+
socket.puts "data: #{@size}"
|
103
|
+
socket.puts @data
|
104
|
+
end
|
105
|
+
socket.puts
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
module_function
|
110
|
+
|
111
|
+
def handle_save(socket, variables, data)
|
112
|
+
path = variables["token"]
|
113
|
+
if File.writable?(path) || !File.exist?(path)
|
114
|
+
$stderr.puts "Saving #{path}" if $settings.verbose
|
115
|
+
begin
|
116
|
+
backup_path = "#{path}~"
|
117
|
+
backup_path = "#{backup_path}~" while File.exist? backup_path
|
118
|
+
FileUtils.cp(path, backup_path, :preserve => true) if File.exist?(path)
|
119
|
+
open(path, 'wb') { |file| file << data }
|
120
|
+
File.unlink(backup_path) if File.exist? backup_path
|
121
|
+
rescue
|
122
|
+
# TODO We probably want some way to notify the server app that the save failed
|
123
|
+
$stderr.puts "Save failed! #{$!}" if $settings.verbose
|
124
|
+
end
|
125
|
+
else
|
126
|
+
$stderr.puts "Skipping save, file not writable." if $settings.verbose
|
115
127
|
end
|
116
|
-
else
|
117
|
-
$stderr.puts "Skipping save, file not writable." if $settings.verbose
|
118
128
|
end
|
119
|
-
end
|
120
129
|
|
121
|
-
def handle_close(socket, variables, data)
|
122
|
-
|
123
|
-
|
124
|
-
end
|
130
|
+
def handle_close(socket, variables, data)
|
131
|
+
path = variables["token"]
|
132
|
+
$stderr.puts "Closed #{path}" if $settings.verbose
|
133
|
+
end
|
125
134
|
|
126
|
-
def handle_cmd(socket)
|
127
|
-
|
135
|
+
def handle_cmd(socket)
|
136
|
+
cmd = socket.readline.chomp
|
128
137
|
|
129
|
-
|
130
|
-
|
138
|
+
variables = {}
|
139
|
+
data = ""
|
131
140
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
141
|
+
while line = socket.readline.chomp
|
142
|
+
break if line.empty?
|
143
|
+
name, value = line.split(': ', 2)
|
144
|
+
variables[name] = value
|
145
|
+
data << socket.read(value.to_i) if name == "data"
|
146
|
+
end
|
147
|
+
variables.delete("data")
|
139
148
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
149
|
+
case cmd
|
150
|
+
when "save" then handle_save(socket, variables, data)
|
151
|
+
when "close" then handle_close(socket, variables, data)
|
152
|
+
else abort "Received unknown command “#{cmd}”, exiting."
|
153
|
+
end
|
144
154
|
end
|
145
|
-
end
|
146
155
|
|
147
|
-
def connect_and_handle_cmds(host, port, cmds)
|
148
|
-
|
149
|
-
|
150
|
-
|
156
|
+
def connect_and_handle_cmds(host, port, cmds)
|
157
|
+
socket = TCPSocket.new(host, port)
|
158
|
+
server_info = socket.readline.chomp
|
159
|
+
$stderr.puts "Connect: ‘#{server_info}’" if $settings.verbose
|
151
160
|
|
152
|
-
|
161
|
+
cmds.each { |cmd| cmd.send(socket) }
|
153
162
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
163
|
+
socket.puts "."
|
164
|
+
handle_cmd(socket) while !socket.eof?
|
165
|
+
socket.close
|
166
|
+
$stderr.puts "Done" if $settings.verbose
|
167
|
+
end
|
158
168
|
end
|
159
169
|
|
160
170
|
## MAIN
|
161
171
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
172
|
+
if __FILE__ == $PROGRAM_NAME
|
173
|
+
$settings = Rmate::Settings.new
|
174
|
+
|
175
|
+
## Parse arguments.
|
176
|
+
cmds = []
|
177
|
+
|
178
|
+
ARGV << '-' if ARGV.empty? and (!$stdin.tty? or $settings.wait)
|
179
|
+
|
180
|
+
ARGV.each_index do |idx|
|
181
|
+
path = ARGV[idx]
|
182
|
+
if path == '-'
|
183
|
+
$stderr.puts "Reading from stdin, press ^D to stop" if $stdin.tty?
|
184
|
+
else
|
185
|
+
abort "'#{path}' is a directory! Aborting." if File.directory? path
|
186
|
+
abort "File #{path} is not writable! Use -f/--force to open anyway." unless $settings.force or File.writable? path or not File.exist? path
|
187
|
+
$stderr.puts "File #{path} is not writable. Opening anyway." if not File.writable? path and File.exist? path and $settings.verbose
|
188
|
+
end
|
189
|
+
cmd = Rmate::Command.new("open")
|
190
|
+
cmd['display-name'] = "#{Socket.gethostname}:untitled (stdin)" if path == '-'
|
191
|
+
cmd['display-name'] = "#{Socket.gethostname}:#{path}" unless path == '-'
|
192
|
+
cmd['display-name'] = $settings.names[idx] if $settings.names.length > idx
|
193
|
+
cmd['real-path'] = File.expand_path(path) unless path == '-'
|
194
|
+
cmd['data-on-save'] = true
|
195
|
+
cmd['re-activate'] = true
|
196
|
+
cmd['token'] = path
|
197
|
+
cmd['selection'] = $settings.lines[idx] if $settings.lines.length > idx
|
198
|
+
cmd['file-type'] = 'txt' if path == '-'
|
199
|
+
cmd['file-type'] = $settings.types[idx] if $settings.types.length > idx
|
200
|
+
cmd.read_stdin if path == '-'
|
201
|
+
cmd.read_file(path) if path != '-' and File.exist? path
|
202
|
+
cmd['data'] = "0" unless path == '-' or File.exist? path
|
203
|
+
cmds << cmd
|
204
|
+
end
|
183
205
|
|
184
|
-
unless $settings.wait
|
185
|
-
|
186
|
-
|
206
|
+
unless $settings.wait
|
207
|
+
pid = fork do
|
208
|
+
Rmate::connect_and_handle_cmds($settings.host, $settings.port, cmds)
|
209
|
+
end
|
210
|
+
Process.detach(pid)
|
211
|
+
else
|
212
|
+
Rmate::connect_and_handle_cmds($settings.host, $settings.port, cmds)
|
187
213
|
end
|
188
|
-
Process.detach(pid)
|
189
|
-
else
|
190
|
-
connect_and_handle_cmds($settings.host, $settings.port, cmds)
|
191
214
|
end
|
data/lib/rmate.rb
CHANGED
@@ -1,5 +1,214 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$VERBOSE = true # -w
|
5
|
+
$KCODE = "U" if RUBY_VERSION < "1.9" # -KU
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
require 'socket'
|
9
|
+
require 'tempfile'
|
10
|
+
require 'yaml'
|
11
|
+
require 'fileutils'
|
2
12
|
|
3
13
|
module Rmate
|
4
|
-
|
14
|
+
DATE = "2013-08-02"
|
15
|
+
VERSION = "1.5.6"
|
16
|
+
VERSION_STRING = "rmate version #{Rmate::VERSION} (#{Rmate::DATE})"
|
17
|
+
|
18
|
+
class Settings
|
19
|
+
attr_accessor :host, :port, :wait, :force, :verbose, :lines, :names, :types
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@host, @port = 'localhost', 52698
|
23
|
+
|
24
|
+
@wait = false
|
25
|
+
@force = false
|
26
|
+
@verbose = false
|
27
|
+
@lines = []
|
28
|
+
@names = []
|
29
|
+
@types = []
|
30
|
+
|
31
|
+
read_disk_settings
|
32
|
+
|
33
|
+
@host = ENV['RMATE_HOST'].to_s if ENV.has_key? 'RMATE_HOST'
|
34
|
+
@port = ENV['RMATE_PORT'].to_i if ENV.has_key? 'RMATE_PORT'
|
35
|
+
|
36
|
+
parse_cli_options
|
37
|
+
|
38
|
+
@host = parse_ssh_connection if @host == 'auto'
|
39
|
+
end
|
40
|
+
|
41
|
+
def read_disk_settings
|
42
|
+
[ "/etc/rmate.rc", "~/.rmate.rc"].each do |current_file|
|
43
|
+
file = File.expand_path current_file
|
44
|
+
if File.exist? file
|
45
|
+
params = YAML::load(File.open(file))
|
46
|
+
@host = params["host"] unless params["host"].nil?
|
47
|
+
@port = params["port"] unless params["port"].nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse_cli_options
|
53
|
+
OptionParser.new do |o|
|
54
|
+
o.on( '--host=name', "Connect to host.", "Use 'auto' to detect the host from SSH.", "Defaults to #{@host}.") { |v| @host = v }
|
55
|
+
o.on('-p', '--port=#', Integer, "Port number to use for connection.", "Defaults to #{@port}.") { |v| @port = v }
|
56
|
+
o.on('-w', '--[no-]wait', 'Wait for file to be closed by TextMate.') { |v| @wait = v }
|
57
|
+
o.on('-l', '--line [NUMBER]', 'Place caret on line [NUMBER] after loading file.') { |v| @lines <<= v }
|
58
|
+
o.on('-m', '--name [NAME]', 'The display name shown in TextMate.') { |v| @names <<= v }
|
59
|
+
o.on('-t', '--type [TYPE]', 'Treat file as having [TYPE].') { |v| @types <<= v }
|
60
|
+
o.on('-f', '--force', 'Open even if the file is not writable.') { |v| @force = v }
|
61
|
+
o.on('-v', '--verbose', 'Verbose logging messages.') { |v| @verbose = v }
|
62
|
+
o.on_tail('-h', '--help', 'Show this message.') { puts o; exit }
|
63
|
+
o.on_tail( '--version', 'Show version.') { puts VERSION_STRING; exit }
|
64
|
+
o.parse!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_ssh_connection
|
69
|
+
ENV['SSH_CONNECTION'].nil? ? 'localhost' : ENV['SSH_CONNECTION'].split(' ').first
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Command
|
74
|
+
def initialize(name)
|
75
|
+
@command = name
|
76
|
+
@variables = {}
|
77
|
+
@data = nil
|
78
|
+
@size = nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def []=(name, value)
|
82
|
+
@variables[name] = value
|
83
|
+
end
|
84
|
+
|
85
|
+
def read_file(path)
|
86
|
+
@size = File.size(path)
|
87
|
+
@data = File.open(path, "rb") { |io| io.read(@size) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_stdin
|
91
|
+
@data = $stdin.read
|
92
|
+
@size = @data.size
|
93
|
+
end
|
94
|
+
|
95
|
+
def send(socket)
|
96
|
+
socket.puts @command
|
97
|
+
@variables.each_pair do |name, value|
|
98
|
+
value = 'yes' if value === true
|
99
|
+
socket.puts "#{name}: #{value}"
|
100
|
+
end
|
101
|
+
if @data
|
102
|
+
socket.puts "data: #{@size}"
|
103
|
+
socket.puts @data
|
104
|
+
end
|
105
|
+
socket.puts
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
module_function
|
110
|
+
|
111
|
+
def handle_save(socket, variables, data)
|
112
|
+
path = variables["token"]
|
113
|
+
if File.writable?(path) || !File.exist?(path)
|
114
|
+
$stderr.puts "Saving #{path}" if $settings.verbose
|
115
|
+
begin
|
116
|
+
backup_path = "#{path}~"
|
117
|
+
backup_path = "#{backup_path}~" while File.exist? backup_path
|
118
|
+
FileUtils.cp(path, backup_path, :preserve => true) if File.exist?(path)
|
119
|
+
open(path, 'wb') { |file| file << data }
|
120
|
+
File.unlink(backup_path) if File.exist? backup_path
|
121
|
+
rescue
|
122
|
+
# TODO We probably want some way to notify the server app that the save failed
|
123
|
+
$stderr.puts "Save failed! #{$!}" if $settings.verbose
|
124
|
+
end
|
125
|
+
else
|
126
|
+
$stderr.puts "Skipping save, file not writable." if $settings.verbose
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def handle_close(socket, variables, data)
|
131
|
+
path = variables["token"]
|
132
|
+
$stderr.puts "Closed #{path}" if $settings.verbose
|
133
|
+
end
|
134
|
+
|
135
|
+
def handle_cmd(socket)
|
136
|
+
cmd = socket.readline.chomp
|
137
|
+
|
138
|
+
variables = {}
|
139
|
+
data = ""
|
140
|
+
|
141
|
+
while line = socket.readline.chomp
|
142
|
+
break if line.empty?
|
143
|
+
name, value = line.split(': ', 2)
|
144
|
+
variables[name] = value
|
145
|
+
data << socket.read(value.to_i) if name == "data"
|
146
|
+
end
|
147
|
+
variables.delete("data")
|
148
|
+
|
149
|
+
case cmd
|
150
|
+
when "save" then handle_save(socket, variables, data)
|
151
|
+
when "close" then handle_close(socket, variables, data)
|
152
|
+
else abort "Received unknown command “#{cmd}”, exiting."
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def connect_and_handle_cmds(host, port, cmds)
|
157
|
+
socket = TCPSocket.new(host, port)
|
158
|
+
server_info = socket.readline.chomp
|
159
|
+
$stderr.puts "Connect: ‘#{server_info}’" if $settings.verbose
|
160
|
+
|
161
|
+
cmds.each { |cmd| cmd.send(socket) }
|
162
|
+
|
163
|
+
socket.puts "."
|
164
|
+
handle_cmd(socket) while !socket.eof?
|
165
|
+
socket.close
|
166
|
+
$stderr.puts "Done" if $settings.verbose
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
## MAIN
|
171
|
+
|
172
|
+
if __FILE__ == $PROGRAM_NAME
|
173
|
+
$settings = Rmate::Settings.new
|
174
|
+
|
175
|
+
## Parse arguments.
|
176
|
+
cmds = []
|
177
|
+
|
178
|
+
ARGV << '-' if ARGV.empty? and (!$stdin.tty? or $settings.wait)
|
179
|
+
|
180
|
+
ARGV.each_index do |idx|
|
181
|
+
path = ARGV[idx]
|
182
|
+
if path == '-'
|
183
|
+
$stderr.puts "Reading from stdin, press ^D to stop" if $stdin.tty?
|
184
|
+
else
|
185
|
+
abort "'#{path}' is a directory! Aborting." if File.directory? path
|
186
|
+
abort "File #{path} is not writable! Use -f/--force to open anyway." unless $settings.force or File.writable? path or not File.exist? path
|
187
|
+
$stderr.puts "File #{path} is not writable. Opening anyway." if not File.writable? path and File.exist? path and $settings.verbose
|
188
|
+
end
|
189
|
+
cmd = Rmate::Command.new("open")
|
190
|
+
cmd['display-name'] = "#{Socket.gethostname}:untitled (stdin)" if path == '-'
|
191
|
+
cmd['display-name'] = "#{Socket.gethostname}:#{path}" unless path == '-'
|
192
|
+
cmd['display-name'] = $settings.names[idx] if $settings.names.length > idx
|
193
|
+
cmd['real-path'] = File.expand_path(path) unless path == '-'
|
194
|
+
cmd['data-on-save'] = true
|
195
|
+
cmd['re-activate'] = true
|
196
|
+
cmd['token'] = path
|
197
|
+
cmd['selection'] = $settings.lines[idx] if $settings.lines.length > idx
|
198
|
+
cmd['file-type'] = 'txt' if path == '-'
|
199
|
+
cmd['file-type'] = $settings.types[idx] if $settings.types.length > idx
|
200
|
+
cmd.read_stdin if path == '-'
|
201
|
+
cmd.read_file(path) if path != '-' and File.exist? path
|
202
|
+
cmd['data'] = "0" unless path == '-' or File.exist? path
|
203
|
+
cmds << cmd
|
204
|
+
end
|
205
|
+
|
206
|
+
unless $settings.wait
|
207
|
+
pid = fork do
|
208
|
+
Rmate::connect_and_handle_cmds($settings.host, $settings.port, cmds)
|
209
|
+
end
|
210
|
+
Process.detach(pid)
|
211
|
+
else
|
212
|
+
Rmate::connect_and_handle_cmds($settings.host, $settings.port, cmds)
|
213
|
+
end
|
5
214
|
end
|
data/rmate.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('
|
2
|
+
require File.expand_path('lib/rmate', File.dirname(__FILE__))
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = 'rmate'
|
@@ -13,5 +13,4 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
14
|
gem.files = `git ls-files`.split("\n")
|
15
15
|
gem.authors = `git log --pretty="format:%an"|sort -u`.split("\n")
|
16
|
-
gem.require_paths = ['lib']
|
17
16
|
end
|
metadata
CHANGED
@@ -1,79 +1,63 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmate
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 1
|
7
|
-
- 5
|
8
|
-
- 5
|
9
|
-
version: 1.5.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.6
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
7
|
+
- Adam Strzelecki
|
12
8
|
- Alex Ross
|
13
9
|
- Allan Odgaard
|
14
|
-
-
|
10
|
+
- Ciarán Walsh
|
15
11
|
- Curt Sellmer
|
16
12
|
- James Edward Gray II
|
17
13
|
- John St. John
|
18
14
|
- Michael Sheets
|
19
15
|
- Nicolas Ledez
|
20
16
|
- OZAWA Sakuro
|
17
|
+
- Richard Myers
|
18
|
+
- Rogelio Gudino
|
21
19
|
- Timothy Andrew
|
22
20
|
- Toby Butzon
|
23
21
|
autorequire:
|
24
22
|
bindir: bin
|
25
23
|
cert_chain: []
|
26
|
-
|
27
|
-
date: 2013-03-17 00:00:00 +01:00
|
28
|
-
default_executable:
|
24
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
29
25
|
dependencies: []
|
30
|
-
|
31
26
|
description: Remote TextMate
|
32
|
-
email:
|
27
|
+
email:
|
33
28
|
- rmate@textmate.org
|
34
|
-
executables:
|
29
|
+
executables:
|
35
30
|
- rmate
|
36
31
|
extensions: []
|
37
|
-
|
38
32
|
extra_rdoc_files: []
|
39
|
-
|
40
|
-
files:
|
33
|
+
files:
|
41
34
|
- Gemfile
|
42
35
|
- README.mdown
|
43
36
|
- Rakefile
|
44
37
|
- bin/rmate
|
45
38
|
- lib/rmate.rb
|
46
|
-
- lib/rmate/version.rb
|
47
39
|
- rmate.gemspec
|
48
|
-
has_rdoc: true
|
49
40
|
homepage: https://github.com/textmate/rmate/
|
50
41
|
licenses: []
|
51
|
-
|
42
|
+
metadata: {}
|
52
43
|
post_install_message:
|
53
44
|
rdoc_options: []
|
54
|
-
|
55
|
-
require_paths:
|
45
|
+
require_paths:
|
56
46
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
segments:
|
69
|
-
- 0
|
70
|
-
version: "0"
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
71
57
|
requirements: []
|
72
|
-
|
73
58
|
rubyforge_project:
|
74
|
-
rubygems_version:
|
59
|
+
rubygems_version: 2.0.3
|
75
60
|
signing_key:
|
76
|
-
specification_version:
|
61
|
+
specification_version: 4
|
77
62
|
summary: Edit files from anywhere in TextMate 2 on your local Mac.
|
78
63
|
test_files: []
|
79
|
-
|
data/lib/rmate/version.rb
DELETED