shell_explain 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 789021ab7ef1c9774f14cd4086d8717203c928f5
4
+ data.tar.gz: dcfa98c2c4041a27f848f6e6a2507d28061815bb
5
+ SHA512:
6
+ metadata.gz: 06143aef944b496f2e64d680c810492c2dfd0e5d1ee9fafb9e8d196e342529318d386f08a175d072cd4cd33cb5c18d387aa7be14fa586de0c4bd074cceecb0f8
7
+ data.tar.gz: a848e24f79783397b1f4152820de93601dc7b34ef7f1994c751b0bb927eecc6294d9a2d37d722ad161086a379605506a87f9981e0930dfa8b2d611d3e8234ec4
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shell_explain.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 blackanger
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # ShellExplain
2
+
3
+ **Explain shell input from your command line.**
4
+
5
+ Thanks http://explainshell.com/
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'shell_explain'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shell_explain
20
+
21
+ ## Usage
22
+
23
+ ```sh
24
+ $ explain "true && { echo success; } || { echo failed; }"
25
+ $ explain "find . -type f -print0"
26
+ $ explain "ssh -i keyfile -f -N -L 1234:www.google.com:80 host"
27
+ $ explain "lsof -c python -u user"
28
+ $ explain "mysql -u root -p -h 192.168.1.2"
29
+ $ explain "iptables -A INPUT -i eth0 -s ip-to-block -j DROP"
30
+ $ explain "git log --graph --abbrev-commit --pretty=oneline origin..mybranch"
31
+ ```
32
+
33
+ ## Screenshots
34
+
35
+ ![alt tag](https://github.com/ZhangHanDong/shell_explain/public/img/explain_shell1.png)
36
+ ![alt tag](https://github.com/ZhangHanDong/shell_explain/public/img/explain_shell2.png)
37
+
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/explain ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ require 'shell_explain'
3
+ require 'ansi/core'
4
+ require 'ansi/progressbar'
5
+
6
+ # example:
7
+ # $ explain "cut -d ' ' -f 1 /var/log/apache2/access_logs | uniq -c | sort -n"
8
+
9
+ # get cmd
10
+ @cmd = ARGV[0]
11
+
12
+ #progress bar
13
+ pbar = ANSI::Progressbar.new("Test Bar", 100)
14
+
15
+ def run(pbar)
16
+ puts "get explain data".ansi(:green)
17
+ pbar.inc
18
+ doc = ShellExplain::Site.get_data(@cmd)
19
+ #commands format: {command: help-num}
20
+ @commands = ShellExplain::Site.get_command(doc)
21
+ @explains = ShellExplain::Site.get_explain(doc)
22
+
23
+ combination = @commands.values.zip(@explains)
24
+
25
+ @results = combination.inject({}) do|h, node|
26
+ h[node[0]] = node[1] unless h.has_key?(node[0])
27
+ h
28
+ end
29
+
30
+ pbar.finish
31
+ end
32
+
33
+ pbar.transfer_mode
34
+ run(pbar)
35
+ puts ("+"*20)+"Explain Shell"+("+"*20)
36
+
37
+ # input results
38
+ # puts "--results: #{@results.inspect}"
39
+
40
+ puts "invalid command".ansi(:red) if @results.empty?
41
+ @results.each do |re|
42
+
43
+ cmd_name = @commands.each_pair do|pair|
44
+ puts pair[0].ansi(:red) if pair.include?(re[0])
45
+ end
46
+
47
+ puts re[1].ansi(:yellow)
48
+ puts ("+"*50).ansi(:green)
49
+ end
50
+
51
+
@@ -0,0 +1,3 @@
1
+ module ShellExplain
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ require "shell_explain/version"
2
+ require 'net/http'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+
6
+ module ShellExplain
7
+ class Site
8
+
9
+ class << self
10
+ def get_data(cmd)
11
+ explain_shell_url = "http://explainshell.com/explain?cmd="
12
+ uri = URI("#{explain_shell_url}#{CGI.escape(cmd)}")
13
+ html = Net::HTTP.get_response(uri).body
14
+ Nokogiri::HTML(html)
15
+ end
16
+
17
+ #{command: help-num}
18
+ def get_command(doc)
19
+ doc.xpath("//span[@helpref]").inject({}) do|cmds, node|
20
+ cmds[node.text] = node.attributes["helpref"].value
21
+ cmds
22
+ end
23
+ end
24
+
25
+ def get_explain(doc)
26
+ data = doc.xpath("//table[@id='help']//pre").inject([]) do|exps, node|
27
+ exps << node.children.text
28
+ end
29
+ data
30
+ end
31
+ end
32
+
33
+ end
34
+ end
data/public/.DS_Store ADDED
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shell_explain/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.name = "shell_explain"
9
+ spec.version = ShellExplain::VERSION
10
+ spec.authors = ["blackanger"]
11
+ spec.email = ["blackanger.z@gmail.com"]
12
+ spec.description = %q{explainshell.com input from terminal}
13
+ spec.summary = %q{explainshell.com for terminal}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "ansi"
23
+ spec.add_dependency "nokogiri"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shell_explain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - blackanger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ansi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: explainshell.com input from terminal
70
+ email:
71
+ - blackanger.z@gmail.com
72
+ executables:
73
+ - explain
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .DS_Store
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/explain
84
+ - lib/shell_explain.rb
85
+ - lib/shell_explain/version.rb
86
+ - public/.DS_Store
87
+ - public/img/.DS_Store
88
+ - public/img/explain_shell1.png
89
+ - public/img/explain_shell2.png
90
+ - shell_explain.gemspec
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: explainshell.com for terminal
115
+ test_files: []