huffshell 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -21,6 +21,14 @@ Features
21
21
  Installation
22
22
  ---------------------
23
23
 
24
+ You need to have zsh_history stored at this location: '~/.zsh_history'. If this code outputs a lot of junk, you are probably setup.
25
+
26
+ ```script
27
+ cat ~/.zsh_history
28
+ ```
29
+
30
+ Here is how you install the gem.
31
+
24
32
  ```script
25
33
  # install it
26
34
  gem install huffman
@@ -31,4 +39,25 @@ huffshell
31
39
 
32
40
  # cleanup
33
41
  alias > ~/.aliases.cache
34
- ```
42
+ ```
43
+
44
+ Fixes
45
+ ---------------------
46
+
47
+ Things don't look right? Change your zsh history to these settings to allow your history to save dups and store a lot of entries. You need dups so that we can figure out what to optimize out with aliases and the larger the history, the better the data will be.
48
+
49
+ ```script
50
+ ## Command history configuration
51
+ HISTFILE=$HOME/.zsh_history
52
+ HISTSIZE=20000
53
+ SAVEHIST=20000
54
+
55
+ setopt append_history
56
+ setopt extended_history
57
+ # setopt hist_expire_dups_first
58
+ # setopt hist_ignore_dups # ignore duplication command history list
59
+ setopt hist_ignore_space
60
+ setopt hist_verify
61
+ setopt inc_append_history
62
+ # setopt share_history # share command history data
63
+ ```
data/bin/huffshell CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'huffshell'
4
- require 'pp'
4
+ require 'colorize'
5
5
 
6
6
  cs = CommandSuggestor.new
7
7
  history_filename = '~/.zsh_history'
@@ -10,5 +10,24 @@ OhMyZshReader.new(history_filename).
10
10
  shell_commands.
11
11
  each{ |l| cs.add(l) }
12
12
 
13
+ puts "Huffshel"
14
+ puts "============="
15
+ puts [cs.commands.size.to_s.green, "unique keywords"].join(" ")
16
+
17
+ puts ""
18
+ [250, 100, 50, 20, 10, 5, 2, 1].reverse.each do |count|
19
+ puts [cs.wordtree.root.minimum(count).keys.size.to_s.green, "commands appear > #{count} times"].join(" ")
20
+ end
21
+
22
+ puts ""
23
+ puts "Most common commands:"
24
+
25
+ cs.wordtree.root.minimum(10).sort{|a, b| a[1].line_count <=> b[1].line_count }.reverse[0,10].each do |word, node|
26
+ puts [node.word, node.line_count.to_s.green].join(" ")
27
+ end
28
+
13
29
  cs.truncate!(30)
30
+
31
+ puts ""
32
+ puts "Command tree:"
14
33
  puts cs.to_print
@@ -15,6 +15,10 @@ class CommandSuggestor
15
15
  wordtree.root.truncate!(minimum)
16
16
  end
17
17
 
18
+ def commands
19
+ wordtree.root.children.keys
20
+ end
21
+
18
22
  def to_print
19
23
  wordtree.root.map do |n|
20
24
  cs = CommandSuggestion.new(n.word_list)
@@ -65,4 +65,8 @@ class WordTreeNode
65
65
  "#{("\t" * (level - 1))}" + "#{word}".green + " #{line_count}:\n"
66
66
  end
67
67
 
68
+ def minimum(min)
69
+ children.select{|k, v| v.line_count >= min }
70
+ end
71
+
68
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huffshell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: