sshx 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/sshx/cli.rb +25 -24
  2. data/lib/sshx/version.rb +1 -1
  3. metadata +2 -2
@@ -9,7 +9,8 @@ module Sshx
9
9
  @@namespace_separator = '.'
10
10
  @@enable_alias = true
11
11
  @@ssh_path = `which ssh`
12
- @@temporary_config_path = '/tmp/sshx_config'
12
+ @@ssh_config_path = @@home_directory + '/.ssh/config'
13
+ @@sshx_config_path = @@home_directory + '/.sshx/config'
13
14
  def start(args = ARGV)
14
15
 
15
16
  if !init()
@@ -17,6 +18,7 @@ module Sshx
17
18
  end
18
19
 
19
20
  load_config()
21
+ make_ssh_config()
20
22
 
21
23
  if args.length == 0
22
24
  puts 'sshx is just a wrapper of ssh.'
@@ -24,11 +26,8 @@ module Sshx
24
26
  return
25
27
  end
26
28
 
27
- make_temporary_config()
28
-
29
29
  if args.length == 2 && args[0] == 'init' && args[1] == '-'
30
30
  puts make_commands().join("\n")
31
- remove_temporary_config()
32
31
  return
33
32
  end
34
33
 
@@ -37,11 +36,9 @@ module Sshx
37
36
  shell_args.push(arg.shellescape)
38
37
  }
39
38
 
40
- system(@@ssh_path + ' ' + shell_args.join(' ') + ' -F ' + @@temporary_config_path)
39
+ system(@@ssh_path + ' ' + shell_args.join(' '))
41
40
  status = $?.exitstatus
42
41
 
43
- remove_temporary_config()
44
-
45
42
  exit status
46
43
 
47
44
  end
@@ -67,7 +64,7 @@ module Sshx
67
64
  puts 'Import ssh config file...'
68
65
 
69
66
  Dir.mkdir(@@home_directory + '/.sshx')
70
- FileUtils.symlink(@@home_directory + '/.ssh/config', @@home_directory + '/.sshx/ssh_config')
67
+ FileUtils.cp(@@home_directory + '/.ssh/config', @@home_directory + '/.sshx/ssh_config')
71
68
 
72
69
  puts 'Make config file...'
73
70
 
@@ -75,7 +72,6 @@ module Sshx
75
72
  file.puts('NamespaceSeparator ' + @@namespace_separator)
76
73
  file.puts('EnableAlias ' + (@@enable_alias?'true':'false'))
77
74
  file.puts('SshPath ' + @@ssh_path)
78
- file.puts('TemporaryConfigPath ' + @@temporary_config_path)
79
75
  }
80
76
 
81
77
  puts 'Edit .bashrc file...'
@@ -114,6 +110,8 @@ module Sshx
114
110
  file = open(@@home_directory + '/.sshx/config')
115
111
  while line = file.gets
116
112
 
113
+ line = line.chomp
114
+
117
115
  matches = line.scan(/NamespaceSeparator\s+([^\s]*)/i)
118
116
  if matches.length > 0
119
117
  @@namespace_separator = matches[0][0]
@@ -132,22 +130,24 @@ module Sshx
132
130
  next
133
131
  end
134
132
 
135
- matches = line.scan(/TemporaryConfigPath\s+([^\s]*)/i)
136
- if matches.length > 0
137
- @@temporary_config_path = matches[0][0]
138
- next
139
- end
140
-
141
133
  end
142
134
  file.close
143
135
 
144
136
  end
145
137
 
146
- def make_temporary_config()
138
+ def make_ssh_config()
147
139
 
148
140
  @@home_directory = File.expand_path('~')
149
141
 
150
142
  configs = []
143
+
144
+ configs.push('#############################################################')
145
+ configs.push('# CAUTION!')
146
+ configs.push('# This config is auto generated by sshx')
147
+ configs.push('# You cannot edit this file. Edit ~/.sshx/ssh_config insted.')
148
+ configs.push('#############################################################')
149
+ configs.push('')
150
+
151
151
  Dir::foreach(@@home_directory + '/.sshx/') {|file_path|
152
152
 
153
153
  if /^\./ =~ file_path
@@ -164,6 +164,8 @@ module Sshx
164
164
 
165
165
  while line = file.gets
166
166
 
167
+ line = line.chomp
168
+
167
169
  matches = line.scan(/Namespace\s+([^\s]+)/i)
168
170
  if matches.length > 0
169
171
  namespace = matches[0][0]
@@ -182,29 +184,28 @@ module Sshx
182
184
 
183
185
  }
184
186
 
185
- file = open(@@temporary_config_path, 'w')
187
+ file = open(@@ssh_config_path, 'w')
186
188
  file.write(configs.join("\n"))
187
189
  file.close
188
190
 
189
191
  end
190
192
 
191
- def remove_temporary_config()
192
-
193
- File.unlink(@@temporary_config_path)
194
-
195
- end
196
-
197
193
  def get_hosts()
198
194
 
199
195
  hosts = []
200
196
 
201
- open(@@temporary_config_path) {|file|
197
+ open(@@ssh_config_path) {|file|
202
198
  while line = file.gets
199
+
200
+ line = line.chomp
201
+
203
202
  matches = line.scan(/Host\s+([^\s]+)/i)
204
203
  if matches.length == 0
205
204
  next
206
205
  end
206
+
207
207
  hosts.push(matches[0][0])
208
+
208
209
  end
209
210
  }
210
211
 
@@ -1,3 +1,3 @@
1
1
  module Sshx
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-08 00:00:00.000000000 Z
12
+ date: 2014-03-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Extended ssh command to use multi ssh_config, namespace and command completion.
15
15
  email: kataoka@sirok.co.jp