zimilar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 165a018850d56fe4f4d59d5a732d97dbeee9448a
4
- data.tar.gz: 06dd3e6e63eda292ee984ba732119538da0b4498
3
+ metadata.gz: 49c0ca0d74d35ec5a238c157ef939af258f20172
4
+ data.tar.gz: 708def047463c1436c0da4494475f1475cbd4f84
5
5
  SHA512:
6
- metadata.gz: b5ac5c88a57b1e5a8e8dae41824ccadd9be647449ef947c4736beb2c0d9b6f46ad9e3e591b04c0ee8b50dd8a4d9aa04fd7a86b9eab6dd22d06d6830a4c5c5c85
7
- data.tar.gz: 1440a20ca6c4c9659e2469962fdd4423249d74d68e0b4d620788c7ba08851173e08837aaad96b0f4e7142a12ae4b5fc6e4d5d2ba165456548fad8b1ae0fc72ed
6
+ metadata.gz: bc1ad1c198101922349824eea7a6773d5ad196dba08da98866ffdd3f00226ce688ef281cd071c272abc601ef18a24951deaa2a2d93ec9a383b83595fb43583fb
7
+ data.tar.gz: 1858c9c65e478aedde8c4c2461e106835200ae115b81847d5a0c8e6cae108f8fc50c119448398ae7aff62404786c4bdf5a628dfdd536dbb3b26ef063312a8aee
metadata CHANGED
@@ -1,61 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zimilar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konrad Lother
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: similar_text
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  description: This small gem extends your shell to autocorrect inputs that would led
42
56
  in a 'command not found'.
43
57
  email:
44
58
  - konrad@corpex.de
45
- executables:
46
- - zimilar
59
+ executables: []
47
60
  extensions: []
48
61
  extra_rdoc_files: []
49
- files:
50
- - .gitignore
51
- - Gemfile
52
- - LICENSE.txt
53
- - README.md
54
- - Rakefile
55
- - bin/zimilar
56
- - lib/zimilar.rb
57
- - lib/zimilar/version.rb
58
- - zimilar.gemspec
62
+ files: []
59
63
  homepage: https://github.com/lotherk/zimilar
60
64
  licenses:
61
65
  - MIT
@@ -66,17 +70,17 @@ require_paths:
66
70
  - lib
67
71
  required_ruby_version: !ruby/object:Gem::Requirement
68
72
  requirements:
69
- - - '>='
73
+ - - ">="
70
74
  - !ruby/object:Gem::Version
71
75
  version: '0'
72
76
  required_rubygems_version: !ruby/object:Gem::Requirement
73
77
  requirements:
74
- - - '>='
78
+ - - ">="
75
79
  - !ruby/object:Gem::Version
76
80
  version: '0'
77
81
  requirements: []
78
82
  rubyforge_project:
79
- rubygems_version: 2.1.10
83
+ rubygems_version: 2.2.2
80
84
  signing_key:
81
85
  specification_version: 4
82
86
  summary: This small gem extends your shell to autocorrect inputs that would led in
data/.gitignore DELETED
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in zimilar.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Konrad Lother
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 DELETED
@@ -1,80 +0,0 @@
1
- # Zimilar
2
-
3
- This small gem extends your shell (see ```Supported Shells```) to autocorrect inputs that would led in a 'command not found'. It basically parses your history file and tries to match to most suitable command found.
4
-
5
- ```zimilar``` is just a small late-night hack I did and might be improved in the future. Its code is currently also not that optimized but for now, it works.
6
-
7
- I also think that it might be better to write this as a native shell function in order to not require ruby to be installed. As times pass by, this might change.
8
-
9
-
10
- ## Supported Shells
11
-
12
- The following shells are supported by now:
13
-
14
- - [zsh](http://www.zsh.org/)
15
- - [bash](https://www.gnu.org/software/bash/bash.html)
16
-
17
- ## Installation
18
-
19
- Install it yourself as:
20
-
21
- $ gem install zimilar
22
-
23
- Install from source:
24
-
25
- $ git clone https://github.com/lotherk/zimilar.git
26
- $ cd zimilar
27
- $ rake build
28
- $ gem install pkg/zimilar-VERSION.gem
29
-
30
- Or simply copy the ```bin/zimilar``` to anywhere you want. Please ensure to install its dependencies.
31
-
32
-
33
- ## How it Works
34
-
35
- ```zimilar``` parses your history file and compares the given command with all commands found in the history. It's using the [similar_text](https://github.com/seph/ruby-similar-text) gem to evaluate the matches.
36
-
37
- If ```zimilar``` finds a suitable match, it replaces your command and runs it.
38
-
39
- ## Usage
40
-
41
- Please be aware of that this is a nightly hack and might, under worst circumstances, destroy all you know and love. Please do not use it without having this read.
42
-
43
- ```zimilar``` doesn't correct to commands with a length less or equal than 2. This is because of most 'dangerous' commands are 2 charackters long, e.g. ```cp```, ```mv```, ```rm``` and many others.
44
-
45
- But still, use it at your own risk.
46
-
47
- ### zsh
48
- Add the following into your .zshrc or any other file that is being ```source```ed during your login:
49
-
50
- ```bash
51
- function command_not_found_handler() {
52
- zimilar $@
53
- }
54
- ```
55
-
56
- ### bash
57
- Add the following into your .bashrc or any other file that is being ```source```ed during your login:
58
-
59
- ```bash
60
- function command_not_found_handle {
61
- zimilar $@
62
- }
63
- ```
64
-
65
-
66
- ## Example
67
- ```
68
- kl@kbook:~/ $ vm
69
- Auto-guessed 'vim', 60.0%
70
- kl@kbook:~/ $
71
-
72
- ```
73
-
74
- ## Contributing
75
-
76
- 1. Fork it ( http://github.com/lotherk/zimilar/fork )
77
- 2. Create your feature branch (`git checkout -b my-new-feature`)
78
- 3. Commit your changes (`git commit -am 'Add some feature'`)
79
- 4. Push to the branch (`git push origin my-new-feature`)
80
- 5. Create new Pull Request
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
data/bin/zimilar DELETED
@@ -1,97 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'similar_text'
3
-
4
- config = {
5
- :zsh => '.zsh_history',
6
- :bash => '.bash_history'
7
- }
8
-
9
- shell = ENV['SHELL'].split("/")[-1].to_sym # auto detect shell
10
-
11
- unless shell
12
- $stderr.puts "could not guess shell, aborting."
13
- exit 1
14
- end
15
-
16
- unless config[shell]
17
- $stderr.puts "unsupported shell '#{shell}'"
18
- exit 1
19
- end
20
-
21
- histfile = ENV['HISTFILE']
22
- histfile ||= ENV['HOME'] + "/" + config[shell]
23
-
24
- unless histfile
25
- $stderr.puts "could not read history file '#{histfile}'"
26
- exit 1
27
- end
28
-
29
- command = ARGV.shift
30
-
31
- # read history - maybe there's a better way?
32
- history = File.read(histfile).split("\n")
33
-
34
- candidates = {}
35
-
36
- history.each do |elem|
37
- next if elem.empty?
38
- line = elem
39
- if elem =~ /^:/ # zsh
40
- time, line = elem.split(";")
41
- next unless line
42
- next if line.strip == command.strip
43
- end
44
- cmd, arg = line.split(" ", 2);
45
- next if cmd.strip == command.strip
46
- next if cmd.length <= 2 # most dangerous commands on unix have a length of 2. like mv, rm, cp, ...
47
-
48
- min = command.length - 1
49
- max = command.length + 1
50
- next unless cmd.length == command.length or cmd.length == min or cmd.length == max
51
-
52
- sim = cmd.similar(command)
53
- sim -= 20 if cmd.length != command.length # hm..
54
- next unless sim >= 60
55
-
56
- candidates[sim] ||= []
57
- next if candidates[sim].include? cmd
58
-
59
- candidates[sim] << cmd
60
- end
61
-
62
- candidates = Hash[candidates.sort_by { |k, v| k.to_f }.reverse.uniq]
63
-
64
- while candidates.count > 0 do
65
- candidate = candidates.shift
66
- sim = candidate[0]
67
- cands = candidate[1]
68
-
69
- if cands.count == 1
70
- begin
71
- puts "Auto-guessed '#{cands[0]}', #{sim.round(2)}%"
72
- slp = case sim
73
- when 0..24 then 5
74
- when 25..49 then 3
75
- when 50..74 then 2
76
- when 75..89 then 1
77
- else 0
78
- end
79
- sleep slp
80
- error = nil
81
- begin
82
- exec cands[0], *ARGV
83
- rescue Exception => e
84
- error = e
85
- end
86
-
87
- exit 0 unless error
88
- rescue
89
- end
90
- elsif cands.count > 1
91
- # abort here, do not iterate them all.
92
- puts "Multiple candidates found:"
93
- puts " " + cands.join(", ")
94
- exit 1
95
- end
96
- end
97
- exit 1
data/lib/zimilar.rb DELETED
@@ -1,5 +0,0 @@
1
- require "zimilar/version"
2
-
3
- module Zimilar
4
- # Your code goes here...
5
- end
@@ -1,3 +0,0 @@
1
- module Zimilar
2
- VERSION = "0.0.2"
3
- end
data/zimilar.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'zimilar/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "zimilar"
8
- spec.version = Zimilar::VERSION
9
- spec.authors = ["Konrad Lother"]
10
- spec.email = ["konrad@corpex.de"]
11
- spec.summary = %q{This small gem extends your shell to autocorrect inputs that would led in a 'command not found'.}
12
- spec.description = %q{This small gem extends your shell to autocorrect inputs that would led in a 'command not found'.}
13
- spec.homepage = "https://github.com/lotherk/zimilar"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "rake"
23
- end