Sha256: 1bfeb6dd6c02eb60a86f3f5735dcf0ee9276bbe9519df1c8184fa7048c1a943f

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby

require 'yaml'
require 'pathname'

Version = '0.1.13'

if ARGV.length == 1 and ARGV[0] == 'version'
    puts Version
    exit
end

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

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.delete_at( ARGV.find_index { |x| x[0, 1] != '-' } || 0 )
Args = ARGV.inject('') { |memo, obj| memo += " '" + obj.gsub(/([$"])/, '\1') + "'" }
Cmd = (ENV.include? 'HSS_DEBUG') ? 'echo ssh' : 'ssh'

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'] + '"'
        exec "#{Cmd} #{long_form} #{Args}"
    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.13 lib/hss