Sha256: 566a2ef8c7b1ab833908fc706a19c91014a755d223c9f1e6725306dbc530acea
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
#!/usr/bin/env ruby require 'yaml' require 'pathname' require 'erb' def expand(input) Conf['expansions'].each { |long, shorts| return long if shorts.include? input } raise NameError, "No expansion found for: #{input}" end def shortcut(input) return Conf['shortcuts'][input] end def command(input) return IO.popen(input) { |cmd| cmd.read } end def default(a, b) a.nil? ? a : b end Debug = (ENV.include? 'HSS_DEBUG') ? true : false possible_paths = [ File.expand_path(ENV['HSS_CONFIG'].to_s), File.expand_path('~/.hss.yml'), Pathname.new(__FILE__).realpath.split()[0].to_s + '/config.yml', ] possible_paths = possible_paths.select { |path| not File.directory? path and File.exists? path } if possible_paths.empty? puts 'No config file found' exit 1 end Conf = open(possible_paths[0]) { |file| YAML.load(file.read) } Input = ARGV.shift Args = ARGV.inject('') { |memo, obj| memo += " '" + obj.gsub(/([$"])/, '\1') + "'" } if Input.nil? or Input == 'help' puts 'How to use:' puts '(what you type) -> (where it takes you)' Conf['patterns'].each { |pattern| puts pattern['example'] } else Conf['patterns'].each do |pattern| next unless Input.match(pattern['short']) long_form = eval '"' + pattern['long'] + '"' #long_form = ERB.new('<%= "' + pattern['long'] + '" %>').result if Debug puts "ssh #{long_form} #{Args}" exit else exec "ssh #{long_form} #{Args}" end end puts "Couldn't find a matching host for: #{Input}" exit 1 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hss-0.1.10 | lib/hss |