Permalink
Browse files

Defaulting to an SSH tunnel friendly configuration and leaving the ol…

…d connection semantics available as a new option.
  • Loading branch information...
1 parent 5d6a14a commit e2f42a2dc5fb7557d115536b5231dc8d9bf7fcc4 @JEG2 JEG2 committed Oct 28, 2011
Showing with 17 additions and 12 deletions.
  1. +17 −12 rmate
View
29 rmate
@@ -14,11 +14,7 @@ class Settings
attr_accessor :host, :port, :wait, :force, :verbose
def initialize
- @host, @port = '127.0.0.1', 52698
-
- if conn = ENV['SSH_CONNECTION']
- @host = conn.split(' ').first
- end
+ @host, @port = 'localhost', 52698
@host = ENV['RMATE_HOST'].to_s if ENV.has_key? 'RMATE_HOST'
@port = ENV['RMATE_PORT'].to_i if ENV.has_key? 'RMATE_PORT'
@@ -37,16 +33,25 @@ class Settings
def parse_cli_options
OptionParser.new do |o|
- o.on( '--host=name', "Connect to host. Defaults to #{@host}.") { |v| @host = v }
- o.on('-p', '--port=#', Integer, "Port number to use for connection. Defaults to #{@port}.") { |v| @port = v }
- o.on('-w', '--[no-]wait', 'Wait for file to be closed by TextMate.') { |v| @wait = v }
- o.on('-f', '--force', 'Open even if the file is not writable.') { |v| @force = v }
- o.on('-v', '--verbose', 'Verbose logging messages.') { |v| @verbose = v }
- o.on_tail('-h', '--help', 'Show this message.') { puts o; exit }
+ o.on( '--host=name', "Connect to host. Defaults to #{@host}.") { |v| @host = v }
+ o.on('-p', '--port=#', Integer, "Port number to use for connection. Defaults to #{@port}.") { |v| @port = v }
+ o.on('-w', '--[no-]wait', 'Wait for file to be closed by TextMate.') { |v| @wait = v }
+ o.on('-f', '--force', 'Open even if the file is not writable.') { |v| @force = v }
+ o.on('-v', '--verbose', 'Verbose logging messages.') { |v| @verbose = v }
+ o.on('-s', '--ssh', 'Use the SSH connection to determine host.') { |v| detect_ssh_connection }
+ o.on_tail('-h', '--help', 'Show this message.') { puts o; exit }
o.on_tail( '--version', 'Show version.') { puts VERSION_STRING; exit }
o.parse!
end
- end
+ end
+
+ private
+
+ def detect_ssh_connection
+ if conn = ENV['SSH_CONNECTION']
+ @host = conn.split(' ').first
+ end
+ end
end
class Command

0 comments on commit e2f42a2

Please sign in to comment.