Sha256: a1687f3582dee9f7fe2db0e5dfd3588f07495d86ffd1525799be84fedb35e71a

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

require 'yaml'
require 'pathname'

Version = '0.1.19'

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? or a.empty?) ? b : a
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'] + '"'
        $stdout.syswrite "\033]0;#{Input}\007" if $stdin.tty? and $stdout.tty?
        exec "#{Cmd} #{long_form} #{Args}"
    end
    puts "Couldn't find a matching host for: #{Input}"
    exit 1
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hss-0.2.0 lib/hss
hss-0.1.19 lib/hss