hss 0.1.19 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7394075b44945605d5279a63b8998a2ea371d23
4
- data.tar.gz: 9e58999eefb44e4ab1395ee2e52c2ce9f98b9c12
3
+ metadata.gz: f97fd7bebd4754a4f541fe572bef404eb40cc54c
4
+ data.tar.gz: eb1f05b133757060a728d495658350e15f156033
5
5
  SHA512:
6
- metadata.gz: d43c9fdf39748fc9018a1ff5a31b0f2e6348d2e4384746f0ad2a80ed8bb26feddd9756d59bfeffd44fa5e98dc93d6180162713fc2440fa2a2af085d948e4b01f
7
- data.tar.gz: 5a5f55c95757bf47a96a65dcf9cf74f48dcfc457f97b2473887af9bcdc9a7d2035e7b530115554e2bf4244e8f1e4599882413a8d7061e756ef394931a0053598
6
+ metadata.gz: 8458ac9a10dfc7f55f611afc1d98c156948fdd19003f0aa6188e89e8cee4b51714cb2eede13de8739e10f36664c11d12c9e806e533aab3fdde692be93d8eab0a
7
+ data.tar.gz: 9304ed0e110094902e659b1724f4dc7ad1e1441bd9868aacf59294cca84b5ea7ce859f0ade3c100e3e6c2eda9cd42113aa2fe7cc44f097276876dc1a05daacf1
data/bin/hss ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hss'
4
+
5
+ My_Handler = HSS::Handler.new ENV['HSS_CONFIG']
6
+
7
+ if ARGV == ['version']
8
+ puts HSS::Version
9
+ exit
10
+ elsif ARGV == ['help'] or ARGV.empty?
11
+ puts 'How to use:'
12
+ puts '(what you type) -> (where it takes you)'
13
+ My_Handler.patterns.each { |pattern| puts pattern['example'] }
14
+ exit
15
+ end
16
+
17
+ Short_Host = ARGV.delete_at( ARGV.find_index { |x| x[0, 1] != '-' } || 0 )
18
+ Args = ARGV.inject('') { |memo, obj| memo += " '" + obj.gsub(/([$"])/, '\1') + "'" }
19
+ Command = (ENV.include? 'HSS_DEBUG') ? 'echo ssh' : 'ssh'
20
+
21
+ Long_Host = My_Handler.handle Short_Host
22
+
23
+ $stdout.syswrite "\033]0;#{Short_Host}\007"
24
+ exec "#{Command} #{Long_Host} #{Args}"
25
+
data/hss.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ require File.join(Dir.pwd, 'lib/hss.rb')
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'hss'
3
- s.version = IO.popen('./lib/hss version') { |cmd| cmd.read }
5
+ s.version = HSS::Version
4
6
  s.date = Time.now.strftime("%Y-%m-%d")
5
7
  s.summary = 'SSH helper'
6
8
  s.description = 'Regex-based SSH shortcut tool'
@@ -0,0 +1,6 @@
1
+ class HSS::Parser
2
+ def command(input)
3
+ return IO.popen(input) { |cmd| cmd.read }
4
+ end
5
+ end
6
+
@@ -0,0 +1,6 @@
1
+ class HSS::Parser
2
+ def default(a, b)
3
+ a.nil? ? a : b
4
+ end
5
+ end
6
+
@@ -0,0 +1,7 @@
1
+ class HSS::Parser
2
+ def expand(input)
3
+ @config['expansions'].each { |long, shorts| return long if shorts.include? input }
4
+ raise NameError, "No expansion found for: #{input}"
5
+ end
6
+ end
7
+
@@ -0,0 +1,6 @@
1
+ class HSS::Parser
2
+ def shortcut(input)
3
+ return @config['shortcuts'][input]
4
+ end
5
+ end
6
+
data/lib/hss.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+ require 'erb'
4
+
5
+ module HSS
6
+ Version = '0.2.0'
7
+ Default_Config = '~/.hss.yml'
8
+ Default_Library = Pathname.new(__FILE__).realpath.split()[0].to_s + '/helpers'
9
+
10
+ class << self
11
+ def new(*args)
12
+ HSS::Handler.new(*args)
13
+ end
14
+ end
15
+
16
+ class Handler
17
+ attr_reader :patterns, :config
18
+
19
+ def initialize(config_path = nil, helper_path = nil)
20
+ load_config(config_path)
21
+ load_parser(helper_path)
22
+ end
23
+
24
+ def load_config(config_path = nil)
25
+ begin
26
+ @config = YAML.load open(File.expand_path(config_path || HSS::Default_Config)).read
27
+ @patterns = @config.delete('patterns')
28
+ rescue
29
+ raise "Failed to load config: #{config_path}"
30
+ end
31
+ end
32
+
33
+ def load_parser(helper_path = nil)
34
+ Dir::glob((helper_path || HSS::Default_Library) + '/*').each do |helper|
35
+ begin
36
+ require_relative helper
37
+ rescue LoadError
38
+ raise LoadError, "Failed to load helper: #{helper}"
39
+ end
40
+ end
41
+ @parser = HSS::Parser.new(@config)
42
+ end
43
+
44
+ def handle(input)
45
+ @patterns.each do |pattern|
46
+ next unless @parser.check(input, pattern['short'])
47
+ return @parser.parse(pattern['long'])
48
+ end
49
+ raise "Couldn't find a matching host for: #{input}"
50
+ end
51
+
52
+ def woof()
53
+ puts "bark"
54
+ end
55
+ end
56
+
57
+ class Parser
58
+ def initialize(config)
59
+ @config = config
60
+ end
61
+
62
+ def check(input, short_form)
63
+ return false unless input.match short_form
64
+ @match_data = binding
65
+ true
66
+ end
67
+ def parse(long_form)
68
+ eval '"' + long_form + '"', @match_data
69
+ end
70
+ end
71
+ end
data/test.conf ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ patterns:
3
+ - note: test
4
+ example: hahahah
5
+ short: '^(\d)([a-z]+)-([fcm])$'
6
+ long: '#{shortcut($2)} #$1 #{expand($3)}'
7
+ expansions:
8
+ fish:
9
+ - f
10
+ monkey:
11
+ - m
12
+ chicken:
13
+ - c
14
+ shortcuts:
15
+ bar: "hello #{expand('c') world"
16
+ ...
17
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: lib
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-11-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Regex-based SSH shortcut tool
14
14
  email: me@lesaker.org
@@ -21,8 +21,15 @@ files:
21
21
  - LICENSE
22
22
  - README.md
23
23
  - Rakefile
24
+ - bin/hss
24
25
  - hss.gemspec
26
+ - lib/helpers/command.rb
27
+ - lib/helpers/default.rb
28
+ - lib/helpers/expand.rb
29
+ - lib/helpers/shortcut.rb
25
30
  - lib/hss
31
+ - lib/hss.rb
32
+ - test.conf
26
33
  homepage: https://github.com/akerl/hss
27
34
  licenses:
28
35
  - MIT