Module: SSHConfig

Defined in:
lib/tmux-connector/ssh_config_parser.rb

Constant Summary collapse

HOST_REGEX =
/^Host (.+)$/

Class Method Summary collapse

Class Method Details

.get_hosts(config_file, reject_re = nil) ⇒ Object



4
5
6
7
8
# File 'lib/tmux-connector/ssh_config_parser.rb', line 4

def self.get_hosts(config_file, reject_re=nil)
  hosts = read_config(config_file).scan(HOST_REGEX).map(&:first).map(&:strip)
  hosts.reject! { |e| e.match reject_re } if reject_re
  return hosts
end

.read_config(config_file) ⇒ Object



10
11
12
13
14
# File 'lib/tmux-connector/ssh_config_parser.rb', line 10

def self.read_config(config_file)
  full_path = File.expand_path config_file
  raise "ssh config file (#{config_file}) not found" unless File.exist? full_path
  return open(full_path).read
end