huffshell 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- huffshell (0.0.4)
4
+ huffshell (0.0.7)
5
5
  colorize
6
6
 
7
7
  GEM
data/bin/huffshell CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'huffshell'
4
- require 'colorize'
5
4
 
6
5
  cs = CommandSuggestor.new
7
6
 
@@ -21,6 +20,8 @@ OhMyZshReader.new(history_filename).
21
20
  shell_commands.
22
21
  each{ |l| cs.add(l) }
23
22
 
23
+ puts cs.wordtree.root.line_count
24
+
24
25
  puts ""
25
26
  puts "============="
26
27
  puts [cs.commands.size.to_s.green, "unique keywords"].join(" ")
@@ -1,5 +1,3 @@
1
- require 'colorize'
2
-
3
1
  class CommandSuggestion
4
2
  attr_accessor :wordlist
5
3
 
@@ -4,7 +4,9 @@ class CommandWord
4
4
  end
5
5
 
6
6
  def self.suggested_letter(word)
7
- word.gsub(/(^\W)+/,"")[0].downcase
7
+ char = word.gsub(/(^\W)+/,"")[0,1].downcase
8
+ return nil if char.empty?
9
+ char
8
10
  rescue
9
11
  nil
10
12
  end
data/lib/huffshell.rb CHANGED
@@ -1,5 +1,21 @@
1
1
  require 'readers/oh_my_zsh_reader'
2
2
 
3
+ # ruby 1.8.6
4
+ class String
5
+ def initial
6
+ self[0,1]
7
+ end
8
+
9
+ def green
10
+ self
11
+ end
12
+ end
13
+
14
+ begin
15
+ require 'colorize'
16
+ rescue LoadError
17
+ end
18
+
3
19
  require 'command/command_word'
4
20
  require 'command/command_suggestor'
5
21
  require 'command/command_suggestion'
@@ -6,7 +6,12 @@ class OhMyZshReader
6
6
  def initialize(file_name)
7
7
  @file_name = file_name
8
8
 
9
- file = File.open(File.expand_path(file_name), 'r')
9
+ path = File.expand_path(file_name)
10
+ if File.exists?(path)
11
+ file = File.open(path, 'r')
12
+ else
13
+ raise "File does not exist." + path.inspect
14
+ end
10
15
 
11
16
  @file_contents = ""
12
17
 
@@ -16,7 +21,7 @@ class OhMyZshReader
16
21
  ic = Iconv.new('UTF-8', 'UTF-8')
17
22
  file.each do |l|
18
23
  begin
19
- @file_contents += ic.iconv(l)
24
+ @file_contents += ic.iconv(l) + "\n"
20
25
  rescue
21
26
  puts "Encoding error: #{l}"
22
27
  end
@@ -30,15 +35,15 @@ class OhMyZshReader
30
35
 
31
36
  private
32
37
 
33
- def filtered_lines
34
- raw_lines(file_contents).select{|l| valid_line?(l) }
38
+ def raw_lines
39
+ file_contents.split("\n")
35
40
  end
36
41
 
37
- def valid_line?(line)
38
- line[0] == ":"
42
+ def filtered_lines
43
+ raw_lines.select{|l| valid_line?(l) }
39
44
  end
40
45
 
41
- def raw_lines(file_contents)
42
- file_contents.split("\n")
46
+ def valid_line?(line)
47
+ line.initial == ":"
43
48
  end
44
49
  end
@@ -6,6 +6,6 @@ class BinaryChecker
6
6
  def exist?
7
7
  # would love something better
8
8
  out = `command -v #{@command} >/dev/null 2>&1`
9
- $?.to_s.scan("exit 0") != []
9
+ $?.to_s.scan("0") != []
10
10
  end
11
11
  end
@@ -18,7 +18,7 @@ class ScriptLine
18
18
  private
19
19
 
20
20
  def comment?
21
- @line[0] == "#"
21
+ @line.initial == "#"
22
22
  end
23
23
 
24
24
  def empty?
@@ -1,5 +1,3 @@
1
- require 'colorize'
2
-
3
1
  class WordTreeNode
4
2
  include Enumerable
5
3
 
@@ -46,7 +44,13 @@ class WordTreeNode
46
44
  end
47
45
 
48
46
  def truncate!(minimum)
49
- children.select!{|k, v| v.line_count >= minimum }
47
+ # Ruby 1.9.2
48
+ # children.select!{|k, v| v.line_count >= minimum }
49
+
50
+ ret = {}
51
+ children.each{|k, v| ret[k] = v if v.line_count >= minimum }
52
+ self.children = ret
53
+
50
54
  children.each{|k, v| v.truncate!(minimum) }
51
55
  end
52
56
 
@@ -66,7 +70,11 @@ class WordTreeNode
66
70
  end
67
71
 
68
72
  def minimum(min)
69
- children.select{|k, v| v.line_count >= min }
73
+ # 1.9.2 compatibility
74
+ # children.select{|k, v| v.line_count >= min }
75
+ ret = {}
76
+ children.each{|k, v| ret[k] = v if v.line_count >= min }
77
+ ret
70
78
  end
71
79
 
72
80
  end
metadata CHANGED
@@ -1,45 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: huffshell
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Paul McKellar
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-06-18 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: colorize
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70228294016280 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- description: A parser and recommendation system for your shell aliases based on your shell history
23
+ prerelease: false
24
+ version_requirements: *70228294016280
25
+ description: A parser and recommendation system for your shell aliases based on your
26
+ shell history
35
27
  email: paul.mckellar@gmail.com
36
- executables:
28
+ executables:
37
29
  - huffshell
38
30
  extensions: []
39
-
40
31
  extra_rdoc_files: []
41
-
42
- files:
32
+ files:
43
33
  - lib/command/command_suggestion.rb
44
34
  - lib/command/command_suggestor.rb
45
35
  - lib/command/command_word.rb
@@ -58,36 +48,26 @@ files:
58
48
  - Readme.md
59
49
  homepage: https://github.com/paulmars/huffshell
60
50
  licenses: []
61
-
62
51
  post_install_message:
63
52
  rdoc_options: []
64
-
65
- require_paths:
53
+ require_paths:
66
54
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
55
+ required_ruby_version: !ruby/object:Gem::Requirement
68
56
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
62
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
85
67
  requirements: []
86
-
87
68
  rubyforge_project:
88
- rubygems_version: 1.8.17
69
+ rubygems_version: 1.8.10
89
70
  signing_key:
90
71
  specification_version: 3
91
72
  summary: Automatic shell alias recommondations based on usage!
92
73
  test_files: []
93
-