Skip to content

Commit

Permalink
Change/fix how we read settings
Browse files Browse the repository at this point in the history
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
sorbits committed Sep 18, 2012
1 parent 310b38c commit e1015e3
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions rmate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e1015e3

Please sign in to comment.