Skip to content
Browse files

Change/fix how we read settings

1. We now have the host default to localhost (again). For most users connecting back to their machine via SSH_CONNECTION will not work (because of NAT/firewall).
3. We now read environment variables after rmate.rc.
2. Previously if user set the host to anything other than ‘auto’ it would be set to ‘localhost’ (bug).
  • Loading branch information...
1 parent 310b38c commit e1015e3467c5596a7658a5056ac8cc33f1f26950 @sorbits sorbits committed Sep 19, 2012
Showing with 17 additions and 16 deletions.
  1. +17 −16 rmate
View
33 rmate
@@ -9,29 +9,26 @@ require 'socket'
require 'tempfile'
require 'yaml'
-VERSION_STRING = 'rmate version 1.4 (2012-08-14)'
+VERSION_STRING = 'rmate version 1.5 (2012-09-19)'
class Settings
attr_accessor :host, :port, :wait, :force, :verbose
def initialize
- @host, @port = 'auto', 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'
+ @host, @port = 'localhost', 52698
@wait = false
@force = false
@verbose = false
read_disk_settings
+
+ @host = ENV['RMATE_HOST'].to_s if ENV.has_key? 'RMATE_HOST'
+ @port = ENV['RMATE_PORT'].to_i if ENV.has_key? 'RMATE_PORT'
+
parse_cli_options
- if @host == 'auto' and (conn = ENV['SSH_CONNECTION'])
- @host = conn.split(' ').first
- else
- @host = 'localhost'
- end
+ @host = parse_ssh_connection if @host == 'auto'
end
def read_disk_settings
@@ -48,15 +45,19 @@ class Settings
def parse_cli_options
OptionParser.new do |o|
o.on( '--host=name', "Connect to host.", "Use 'auto' to detect the host from SSH.", "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_tail( '--version', 'Show version.') { puts VERSION_STRING; exit }
+ 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_tail( '--version', 'Show version.') { puts VERSION_STRING; exit }
o.parse!
end
end
+
+ def parse_ssh_connection
+ ENV['SSH_CONNECTION'].nil? ? 'localhost' : ENV['SSH_CONNECTION'].split(' ').first
+ end
end
class Command

0 comments on commit e1015e3

Please sign in to comment.
Something went wrong with that request. Please try again.