sshez 0.1.0 → 0.2.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -7
  3. data/lib/sshez.rb +44 -13
  4. data/lib/sshez/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22f9add4fa0d691c5a71d7dd7daa3e773628208d
4
- data.tar.gz: 294c4104b066e068315ed456c6e671e27d32e8e0
3
+ metadata.gz: cec6ed214de47ce94ced8d951f0d17d5396b3281
4
+ data.tar.gz: 340865e6e375fe4389f3a7a2e2e2860e75bcf6e0
5
5
  SHA512:
6
- metadata.gz: 0c93f02bb17e20f988e4ca633730f597c9414a1f0af132fcc173045a27e77ba3c7b17f101e49ef3d6092ac837440a8832a86bf7d66c414e0d4f815714872c536
7
- data.tar.gz: d8ae9b319b8a78c42593369f5e343e18c4b90d55833706a443da150feebea226b8f8a35be3e92568b828ba64504fb4b99870481028e310fbdb6ff8acab28f1a0
6
+ metadata.gz: ef73d905d7aad616af3035a4e2efb4c7d391701aaacd1ee02afc813454794598a72faf9236bfe96a0f1fef2ce2aa5dbce40d36231020877b035bd90f9ba0bb61
7
+ data.tar.gz: 2c4d2dd8e939aecf1cfd5d78ecd331fa2d11fba4f1ad1fbab6be4eb17e5816c518f737f4e19b0aaafc5856b9758a55082feec367a5874488ea92aac08e1cba1b
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Sshez
2
+ [![Gem Version](https://badge.fury.io/rb/sshez.svg)](https://badge.fury.io/rb/sshez)
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sshez`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ If you have multiple servers that you access on daily bases! sshez helps you configure your ssh/config file so you will never need to remember ip or ports again.
5
+
6
+ ### Example
7
+
8
+ sshez mw_server root@74.125.224.72 -p 120
9
+
10
+ you will be able to use
11
+
12
+ ssh mw_server
13
+
4
14
 
5
- TODO: Delete this and the text above, and describe your gem
6
15
 
7
16
  ## Installation
8
17
 
@@ -24,7 +33,7 @@ Or install it yourself as:
24
33
 
25
34
  try sshez -h
26
35
 
27
- Usage: sshez user@ip [options]
36
+ Usage: sshez aliase user@ip [options]
28
37
 
29
38
  Specific options:
30
39
  -p, --port PORT Specify a port
@@ -49,10 +58,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Gomaak
49
58
 
50
59
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
60
 
52
- ## Output
53
- sshez where you don't have to remember your ips or deal with ssh config
54
-
55
- Show version
56
61
 
57
62
 
58
63
  ## Missing
@@ -60,3 +65,8 @@ sshez where you don't have to remember your ips or deal with ssh config
60
65
  * All the other options in [ssh documentation](http://linux.die.net/man/5/ssh_config)
61
66
  * Add -r option to remove aliases
62
67
 
68
+ ## Credit
69
+
70
+ Mohamed Ossama who gave me this idea
71
+
72
+
data/lib/sshez.rb CHANGED
@@ -17,7 +17,7 @@ module Sshez
17
17
  options = OpenStruct.new
18
18
 
19
19
  opt_parser = OptionParser.new do |opts|
20
- opts.banner = "Usage: sshez name user@ip [options]"
20
+ opts.banner = "Usage: sshez alias (role@host|-r) [options]"
21
21
 
22
22
  opts.separator ""
23
23
  opts.separator "Specific options:"
@@ -75,27 +75,58 @@ module Sshez
75
75
  file.close
76
76
  end
77
77
  output += "to #{file_path}\n"
78
+ output += "try ssh #{name} \n"
78
79
 
79
80
  output
80
81
  end
81
82
 
82
83
  def self.form(name, user, host, options)
83
- retuned = %Q|Host #{name}
84
- HostName #{host}
85
- User #{user}
86
- |
84
+ retuned = "\n"
85
+ retuned += "Host #{name}\n"
86
+ retuned += " HostName #{host}\n"
87
+ retuned += " User #{user}\n"
88
+
87
89
  if options.port
88
- retuned += %Q| Port #{options.port}
89
- |
90
+ retuned += " Port #{options.port}\n"
90
91
  end
91
92
 
92
93
  if options.identity_file
93
- retuned += %Q| IdentityFile #{options.identity_file}
94
- |
94
+ retuned += " IdentityFile #{options.identity_file}\n"
95
95
  end
96
96
  retuned
97
97
 
98
98
  end
99
+
100
+ def self.remove(name)
101
+ output = ""
102
+ started_removing = false
103
+ file_path = File.expand_path('~')+"/.ssh/config"
104
+ file = File.open(file_path, "r")
105
+ new_file = File.open(file_path+"temp", "w")
106
+ file.each do |line|
107
+ if line.include?("Host #{name}")|| started_removing
108
+ if started_removing && line.include?("Host ") && !line.include?(name)
109
+ started_removing = false
110
+ else
111
+ output += line
112
+ started_removing = true
113
+ end
114
+ else
115
+ new_file.write(line)
116
+ end
117
+ end
118
+ file.close
119
+ new_file.close
120
+ File.delete(file_path)
121
+ File.rename(file_path+"temp", file_path)
122
+
123
+ if output.empty?
124
+ return "could not find host (#{name})"
125
+ else
126
+ return output
127
+ end
128
+
129
+ end
99
130
 
100
131
 
101
132
 
@@ -105,10 +136,12 @@ module Sshez
105
136
 
106
137
  def process(args)
107
138
  # parse the params to get the options
108
- if (args.length < 2 || !args[1].include?("@"))
139
+ if (args.length < 2 || !args[1].include?("@") || args[0][0] == '-')
109
140
  if args[0] == "-h"
110
141
  Params.parse(args)
111
142
  return nil
143
+ elsif ['-r', "--remove"].include?(args[1])
144
+ return ConfigFile.remove(args[0])
112
145
  end
113
146
  output = %Q|Invalid input
114
147
  Use -h for help|
@@ -117,9 +150,7 @@ module Sshez
117
150
  options = Params.parse(args)
118
151
 
119
152
 
120
- if options.remove
121
- "Not implemented :("
122
- else
153
+ unless options.remove
123
154
  user, host = args[1].split("@")
124
155
  output = ConfigFile.append(args[0], user, host, options)
125
156
  output + "Done!"
data/lib/sshez/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sshez
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshez
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Immortal Friday
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-05 00:00:00.000000000 Z
11
+ date: 2015-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler