sshmenu 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sshmenu/actions.rb +10 -14
- data/lib/sshmenu/config.rb +7 -7
- data/lib/sshmenu/options.rb +5 -7
- data/lib/sshmenu/selector.rb +17 -12
- data/lib/sshmenu/version.rb +1 -1
- data/lib/sshmenu.rb +16 -18
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8965529a56d459ff2f1e1697088fa5a5f6e31d50
|
4
|
+
data.tar.gz: b1f9a37eb1b8370506d0fcdc1bf9f92911752f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb309e44d8c81ac1bfd58c40ef3d49d3e5eb6098610f4efb947a7115f3db95021c44f1af6517effdb973417834c65435eb3166618fd3c949f4967caebffd6ef9
|
7
|
+
data.tar.gz: 3ecc3a63b1e664b441db749d6997e3ea233a67ee2354e7483920fdf6a84591000bb40dfa984f162ce2f42c684f71130e54780ae8a67d51d390e53243341c9ca4
|
data/lib/sshmenu/actions.rb
CHANGED
@@ -10,22 +10,19 @@ module SshMenu
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def edit
|
13
|
-
puts "Edit config file
|
14
|
-
exec("#{@general['editor']}
|
13
|
+
puts "Edit config file #@config_file"
|
14
|
+
exec("#{@general['editor']} #@config_file")
|
15
15
|
end
|
16
16
|
|
17
17
|
def connect(index)
|
18
|
-
unless index.between?(0, @connections.length-1)
|
19
|
-
raise ArgumentError, 'invalid index'
|
20
|
-
end
|
21
|
-
|
22
18
|
conn = @connections[index]
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
cmd = [@general['ssh_exec'],
|
21
|
+
@general['ssh_opts'],
|
22
|
+
conn['ssh_opts'],
|
23
|
+
conn['user_host']
|
24
|
+
].join(' ')
|
25
|
+
puts "Command is #{cmd}" if $DEBUG
|
29
26
|
puts "Connecting to #{conn['user_host']}"
|
30
27
|
exec(cmd)
|
31
28
|
end
|
@@ -34,9 +31,8 @@ module SshMenu
|
|
34
31
|
editor = Config.default_editor
|
35
32
|
config = Config.default_config_file
|
36
33
|
print "Edit #{config} using default editor '#{editor}' [y/N]? "
|
37
|
-
|
38
|
-
|
39
|
-
end
|
34
|
+
|
35
|
+
exec("#{editor} #{config}") if STDIN.getc[/[Yy]/]
|
40
36
|
end
|
41
37
|
|
42
38
|
end
|
data/lib/sshmenu/config.rb
CHANGED
@@ -22,7 +22,7 @@ module SshMenu
|
|
22
22
|
@general = config['general']
|
23
23
|
@connections = config['connections']
|
24
24
|
|
25
|
-
puts "Config is #{config.inspect}" if
|
25
|
+
puts "Config is #{config.inspect}" if $DEBUG
|
26
26
|
rescue Psych::SyntaxError => e
|
27
27
|
raise ConfigException, "YAML syntax error: #{e.message}"
|
28
28
|
end
|
@@ -38,11 +38,11 @@ module SshMenu
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def create_config_file(cfg_file)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
puts "Create sample config file #{cfg_file}"
|
42
|
+
project_dir = File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))
|
43
|
+
sample_cfg = File.join(project_dir, 'data', 'sshmenu', 'sampleconfig.yml');
|
44
|
+
FileUtils.mkdir_p(File.dirname(cfg_file))
|
45
|
+
FileUtils.cp(sample_cfg, cfg_file)
|
46
46
|
end
|
47
47
|
|
48
48
|
def validate_config(config)
|
@@ -58,7 +58,7 @@ module SshMenu
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.default_ssh_client
|
61
|
-
|
61
|
+
'ssh'
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.default_editor
|
data/lib/sshmenu/options.rb
CHANGED
@@ -13,7 +13,7 @@ module SshMenu
|
|
13
13
|
opts.banner << "add no arguments to show a list of configured connections"
|
14
14
|
|
15
15
|
opts.on('-e', '--edit', 'edit configuration file') do |e|
|
16
|
-
@opts
|
16
|
+
@opts[:action] = :edit
|
17
17
|
end
|
18
18
|
|
19
19
|
opts.on_tail('-v', '--version', 'print version') do
|
@@ -29,12 +29,10 @@ module SshMenu
|
|
29
29
|
|
30
30
|
opt_parser.parse!(args)
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
raise "'#{args[0]}' expected to be a preselected index"
|
37
|
-
end
|
32
|
+
begin
|
33
|
+
@opts[:index] = Integer(args.first) - 1 if args.first
|
34
|
+
rescue ArgumentError
|
35
|
+
raise "'#{args.first}' expected to be a preselected index"
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
data/lib/sshmenu/selector.rb
CHANGED
@@ -7,19 +7,25 @@ module SshMenu
|
|
7
7
|
|
8
8
|
def select
|
9
9
|
selection = request_selection
|
10
|
-
|
10
|
+
|
11
11
|
case selection
|
12
12
|
when /\A[eE]\z/
|
13
13
|
{:action => :edit}
|
14
|
-
when /\A[1-9][0-9]*\z/
|
15
|
-
|
14
|
+
when (/\A[1-9][0-9]*\z/)
|
15
|
+
index = Integer(selection) - 1
|
16
|
+
raise_invalid unless index.between?(0, @connections.length - 1)
|
17
|
+
{:index => index}
|
16
18
|
when /\A\z/
|
17
19
|
{}
|
18
20
|
else
|
19
|
-
|
21
|
+
raise_invalid
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
25
|
+
def raise_invalid
|
26
|
+
raise ArgumentError, 'selection must be an index from the list'
|
27
|
+
end
|
28
|
+
|
23
29
|
def request_selection
|
24
30
|
puts connection_list
|
25
31
|
print 'Pick a server (or e to edit connections): '
|
@@ -30,14 +36,13 @@ module SshMenu
|
|
30
36
|
uh_length = @connections.map {|conn| conn['user_host'].length}.max
|
31
37
|
index_length = @connections.size.to_s.length
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
@connections.each.with_index.each_with_object(StringIO.new) do |(connection, index), concat|
|
40
|
+
concat << "%#{index_length}d) %-#{uh_length+3}s %s\n" % [
|
41
|
+
index + 1,
|
42
|
+
connection['user_host'],
|
43
|
+
connection['description']
|
44
|
+
]
|
45
|
+
end.string
|
40
46
|
end
|
41
|
-
|
42
47
|
end
|
43
48
|
end
|
data/lib/sshmenu/version.rb
CHANGED
data/lib/sshmenu.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
require 'sshmenu/selector'
|
1
|
+
%w(options config selector actions).each do |req|
|
2
|
+
require "sshmenu/#{req}"
|
3
|
+
end
|
5
4
|
|
6
5
|
module SshMenu
|
7
6
|
class SshMenu
|
@@ -10,21 +9,20 @@ module SshMenu
|
|
10
9
|
config = Config.new
|
11
10
|
actions = Actions.new(config)
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
selection = if options.empty?
|
13
|
+
Selector.new(config.connections).select
|
14
|
+
else
|
15
|
+
options
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
18
|
+
actions.edit if selection[:action] == :edit
|
19
|
+
actions.connect selection[:index] if selection[:index]
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
rescue ConfigException => e
|
22
|
+
puts e.message
|
23
|
+
Actions.ask_edit_with_default_editor
|
24
|
+
rescue => e
|
25
|
+
puts(e.message) unless $DEBUG
|
26
|
+
end
|
28
27
|
end
|
29
28
|
end
|
30
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshmenu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
version: '11.2'
|
27
27
|
description: |
|
28
28
|
This gem provides the executable 'sshmenu', which brings up
|
29
|
-
a list of configured ssh
|
29
|
+
a list of configured ssh connections. From the list you can
|
30
30
|
directly connect to one of the ssh servers or edit the
|
31
31
|
available ssh connections.
|
32
32
|
email:
|
@@ -48,7 +48,7 @@ homepage: http://rubygems.org/gems/sshmenu
|
|
48
48
|
licenses:
|
49
49
|
- GPL-2.0
|
50
50
|
metadata: {}
|
51
|
-
post_install_message: Type sshmenu -e to start editing
|
51
|
+
post_install_message: Type sshmenu -e to start editing your ssh connections
|
52
52
|
rdoc_options: []
|
53
53
|
require_paths:
|
54
54
|
- lib
|