sshy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/README.md +10 -3
- data/bin/sshy +114 -0
- data/lib/sshy.rb +8 -2
- data/lib/sshy/data.rb +94 -0
- data/lib/sshy/version.rb +1 -1
- data/spec/foobar_spec.rb +6 -0
- data/spec/spec_helper.rb +9 -0
- data/sshy.gemspec +3 -0
- metadata +40 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc20369e84dc0f45b91dbc14f62f4e7b156994dd
|
4
|
+
data.tar.gz: 1273d6e52ad6611b0525471cb053a8c2d6e699a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52526406101ded5171a14e8799ad450f4633bea354b3a0c60d96cc74f10c496e2d83a999cccc0653a8cce026bdf028ff98f4aaf8c5f6542a87e92bd3a79d8d7f
|
7
|
+
data.tar.gz: 901d5bf1cbbcdec99cf0f7200971df49784d273ecd213860a71744eca2191b66ae01a9c8196657826db2fcdf4a6642f6bb019c582fb2093ca287f189d04b1061
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# SSHY
|
2
2
|
|
3
|
-
|
3
|
+
_version 0.0.2_
|
4
|
+
|
5
|
+
Sshy help you connect to your ssh server without remember every name of it.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -20,7 +22,12 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
25
|
+
```
|
26
|
+
$ sshy
|
27
|
+
server01 server02 server03 server04
|
28
|
+
server05
|
29
|
+
```
|
30
|
+
And now you could select one and press `Enter` to ssh it
|
24
31
|
|
25
32
|
## Contributing
|
26
33
|
|
data/bin/sshy
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'terminal-table'
|
3
|
+
require 'io/console'
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
Bundler.setup
|
7
|
+
require_relative '../lib/sshy'
|
8
|
+
|
9
|
+
|
10
|
+
# puts Sshy::VERSION
|
11
|
+
HIDE_CURSOR = "/usr/bin/tput civis"
|
12
|
+
SHOW_CURSOR = "/usr/bin/tput cnorm"
|
13
|
+
|
14
|
+
_table_size = [3, 3]
|
15
|
+
_x_y = [0, 0]
|
16
|
+
|
17
|
+
# TODO: check windows size >= ?
|
18
|
+
def winsize
|
19
|
+
IO.console.winsize
|
20
|
+
rescue LoadError
|
21
|
+
[Integer(`tput li`), Integer(`tput co`)]
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_hosts
|
25
|
+
hosts = []
|
26
|
+
f = File.open("#{Dir.home}/.ssh/config", "r")
|
27
|
+
f.each_line do |line|
|
28
|
+
if /^Host\s/.match(line)
|
29
|
+
hosts << line.split(' ').last
|
30
|
+
end
|
31
|
+
end
|
32
|
+
f.close
|
33
|
+
|
34
|
+
hosts.sort!
|
35
|
+
end
|
36
|
+
|
37
|
+
def formattd_output(rows)
|
38
|
+
table = Terminal::Table.new :rows => rows
|
39
|
+
table.style = {:width => 100, :border_x => " ", :border_i => " ", :border_y => " "}
|
40
|
+
return table
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_char
|
44
|
+
STDIN.echo = false
|
45
|
+
STDIN.raw!
|
46
|
+
|
47
|
+
input = STDIN.getc.chr
|
48
|
+
if input == "\e" then
|
49
|
+
input << STDIN.read_nonblock(3) rescue nil
|
50
|
+
input << STDIN.read_nonblock(2) rescue nil
|
51
|
+
end
|
52
|
+
ensure
|
53
|
+
STDIN.echo = true
|
54
|
+
STDIN.cooked!
|
55
|
+
|
56
|
+
return input
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
system(HIDE_CURSOR) # hide cursor
|
61
|
+
|
62
|
+
begin
|
63
|
+
hosts = get_hosts
|
64
|
+
data = Sshy::Data.new hosts
|
65
|
+
|
66
|
+
arrow_key = ''
|
67
|
+
while true do
|
68
|
+
data.move(arrow_key)
|
69
|
+
table = formattd_output(data.output)
|
70
|
+
|
71
|
+
# refresh new output
|
72
|
+
puts table
|
73
|
+
|
74
|
+
# read input
|
75
|
+
char = read_char
|
76
|
+
if char == 'q' or char == "\u0003" # Ctrl-C
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
case char
|
80
|
+
when "\r"
|
81
|
+
# open ssh
|
82
|
+
location = data.location
|
83
|
+
pid = Process.fork
|
84
|
+
if pid.nil? then
|
85
|
+
command = "open ssh://#{data.data[location[1]][location[0]]}"
|
86
|
+
puts "`#{command}`" + ' now'
|
87
|
+
exec command
|
88
|
+
else
|
89
|
+
Process.detach(pid)
|
90
|
+
puts "exit"
|
91
|
+
end
|
92
|
+
#Process.wait pid
|
93
|
+
exit
|
94
|
+
when "\e[A", "\u0010", 'k' # UP, CTRL-P, k
|
95
|
+
arrow_key = 'up'
|
96
|
+
when "\e[B", "\u000E", 'j' # DOWN, CTRL-N, j
|
97
|
+
arrow_key = 'down'
|
98
|
+
when "\e[C", "\u0006", 'l' # RIGHT, CTRL-F, l
|
99
|
+
arrow_key = 'right'
|
100
|
+
when "\e[D", "\u0002", 'h' # LEFT, CTRL-B, h
|
101
|
+
arrow_key = 'left'
|
102
|
+
end
|
103
|
+
|
104
|
+
# clear old output
|
105
|
+
(data.length + 2).times do
|
106
|
+
system('/usr/bin/tput cuu1')
|
107
|
+
system('/usr/bin/tput el')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
rescue Interrupt
|
111
|
+
exit
|
112
|
+
ensure
|
113
|
+
system(SHOW_CURSOR) # show cursor
|
114
|
+
end
|
data/lib/sshy.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
require
|
1
|
+
# require all files
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
%w(version).each do |file|
|
4
|
+
require "sshy/#{file}"
|
5
|
+
end
|
2
6
|
|
3
7
|
module Sshy
|
4
|
-
|
8
|
+
require 'sshy/data'
|
9
|
+
autoload :VERSION, 'sshy/version'
|
10
|
+
#autoload :Data, 'sshy/data'
|
5
11
|
end
|
data/lib/sshy/data.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
module Sshy
|
4
|
+
class Data
|
5
|
+
def initialize(array, width = 3)
|
6
|
+
@data = to_nested_array array, width
|
7
|
+
|
8
|
+
#@data = [['server01', 'server02', 'server09'],
|
9
|
+
# ['server03', 'server04', 'server00', 'hahaha'],
|
10
|
+
# ['server05'],
|
11
|
+
# ['server03', 'server04', 'server00', 'hahaha'],
|
12
|
+
# ['server07', 'server08'],
|
13
|
+
# ['server11', 'server12', '000000', '222', '1', '2']]
|
14
|
+
@location = [0, 2]
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_nested_array(array, width)
|
18
|
+
length = array.length
|
19
|
+
rows = []
|
20
|
+
tmp_array = []
|
21
|
+
i = 0
|
22
|
+
while i < length do
|
23
|
+
j = 0
|
24
|
+
while j < width do
|
25
|
+
tmp_array << array[i] if i < length
|
26
|
+
j += 1
|
27
|
+
i += 1
|
28
|
+
end
|
29
|
+
rows << tmp_array
|
30
|
+
tmp_array = []
|
31
|
+
end
|
32
|
+
rows
|
33
|
+
end
|
34
|
+
|
35
|
+
def move(key)
|
36
|
+
case key
|
37
|
+
when ""
|
38
|
+
when 'up'
|
39
|
+
move_up
|
40
|
+
when 'down'
|
41
|
+
move_down
|
42
|
+
when 'left'
|
43
|
+
move_left
|
44
|
+
when 'right'
|
45
|
+
move_right
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def output
|
50
|
+
data = Marshal.load(Marshal.dump(@data))
|
51
|
+
|
52
|
+
# location check, if there is element in data
|
53
|
+
length = data[@location[1]].length - 1
|
54
|
+
if @location[0] > length
|
55
|
+
@location[0] = length
|
56
|
+
end
|
57
|
+
|
58
|
+
data[@location[1]][@location[0]] =
|
59
|
+
data[@location[1]][@location[0]].colorize(:color => :red, :mode => :bold)
|
60
|
+
|
61
|
+
return data
|
62
|
+
end
|
63
|
+
|
64
|
+
def length
|
65
|
+
return @data.length
|
66
|
+
end
|
67
|
+
|
68
|
+
def move_up
|
69
|
+
@location[1] -= 1 if @location[1] > 0
|
70
|
+
end
|
71
|
+
|
72
|
+
def move_down
|
73
|
+
@location[1] += 1 if @location[1] < (@data.length - 1)
|
74
|
+
end
|
75
|
+
|
76
|
+
def move_left
|
77
|
+
@location[0] -= 1 if @location[0] > 0
|
78
|
+
end
|
79
|
+
|
80
|
+
def move_right
|
81
|
+
@location[0] += 1 if @location[0] < (@data[@location[1]].length - 1)
|
82
|
+
end
|
83
|
+
|
84
|
+
def location
|
85
|
+
@location
|
86
|
+
end
|
87
|
+
|
88
|
+
def data
|
89
|
+
@data
|
90
|
+
end
|
91
|
+
|
92
|
+
private :move_up, :move_down, :move_left, :move_right
|
93
|
+
end
|
94
|
+
end
|
data/lib/sshy/version.rb
CHANGED
data/spec/foobar_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/sshy.gemspec
CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency 'colorize', '>= 0.7.5'
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
23
26
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shown Tien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.5
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,22 +52,42 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
41
69
|
description: Sshy help you connect to your ssh server without remember every name
|
42
70
|
of it.
|
43
71
|
email:
|
44
72
|
- hightian@gmail.com
|
45
|
-
executables:
|
73
|
+
executables:
|
74
|
+
- sshy
|
46
75
|
extensions: []
|
47
76
|
extra_rdoc_files: []
|
48
77
|
files:
|
49
78
|
- ".gitignore"
|
79
|
+
- ".rspec"
|
50
80
|
- Gemfile
|
51
81
|
- LICENSE
|
52
82
|
- LICENSE.txt
|
53
83
|
- README.md
|
54
84
|
- Rakefile
|
85
|
+
- bin/sshy
|
55
86
|
- lib/sshy.rb
|
87
|
+
- lib/sshy/data.rb
|
56
88
|
- lib/sshy/version.rb
|
89
|
+
- spec/foobar_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
57
91
|
- sshy.gemspec
|
58
92
|
homepage: https://github.com/wenxer/sshy
|
59
93
|
licenses:
|
@@ -79,4 +113,6 @@ rubygems_version: 2.4.4
|
|
79
113
|
signing_key:
|
80
114
|
specification_version: 4
|
81
115
|
summary: SSH Tool
|
82
|
-
test_files:
|
116
|
+
test_files:
|
117
|
+
- spec/foobar_spec.rb
|
118
|
+
- spec/spec_helper.rb
|