huffshell 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Readme.md +1 -1
- data/bin/huffshell +11 -12
- data/lib/huffshell.rb +3 -2
- data/lib/readers/history_reader.rb +65 -0
- data/lib/readers/oh_my_zsh_reader.rb +1 -31
- data/lib/tree/word_tree_node.rb +1 -1
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Huffshell
|
2
2
|
====================
|
3
3
|
|
4
|
-
Huffshell is a gem for optimizing your
|
4
|
+
Huffshell is a gem for optimizing your aliases, programmatically.
|
5
5
|
|
6
6
|
Huffshell looks at your shell history and generates aliases based on your typical usage. Memorable and short commands are suggested for the most common things you type to save you the most keystrokes.
|
7
7
|
|
data/bin/huffshell
CHANGED
@@ -4,21 +4,20 @@ require 'huffshell'
|
|
4
4
|
|
5
5
|
cs = CommandSuggestor.new
|
6
6
|
|
7
|
-
# TODOS
|
8
|
-
# get largest history file
|
9
|
-
# examine to see what format the file is in
|
10
|
-
# let users tell me where their files is
|
11
|
-
|
12
|
-
files = ['~/.zsh_history', '~/.zshhistory', '~/.zhistory']
|
13
|
-
history_filename = files.map{|f| File.expand_path(f) }.select{|f| File.exist?(f) }.first
|
14
|
-
|
15
7
|
puts "Huffshell"
|
16
8
|
puts "============="
|
17
|
-
puts ["History found:", history_filename, File.size(history_filename).to_s].join(" ")
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
history_files = HistoryReader.files
|
11
|
+
|
12
|
+
history_files.each do |history_filename|
|
13
|
+
if HistoryReader.timestamps?(history_filename)
|
14
|
+
shell_commands = OhMyZshReader.new(history_filename).shell_commands
|
15
|
+
else
|
16
|
+
shell_commands = HistoryReader.new(history_filename).shell_commands
|
17
|
+
end
|
18
|
+
puts "Importing #{history_filename} #{shell_commands.size} commands found"
|
19
|
+
shell_commands.each{ |l| cs.add(l) }
|
20
|
+
end
|
22
21
|
|
23
22
|
puts cs.wordtree.root.line_count
|
24
23
|
|
data/lib/huffshell.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'readers/oh_my_zsh_reader'
|
2
|
-
|
3
1
|
# ruby 1.8.6
|
4
2
|
class String
|
5
3
|
def initial
|
@@ -16,6 +14,9 @@ begin
|
|
16
14
|
rescue LoadError
|
17
15
|
end
|
18
16
|
|
17
|
+
require 'readers/history_reader'
|
18
|
+
require 'readers/oh_my_zsh_reader'
|
19
|
+
|
19
20
|
require 'command/command_word'
|
20
21
|
require 'command/command_suggestor'
|
21
22
|
require 'command/command_suggestion'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class HistoryReader
|
2
|
+
attr_accessor :filename, :file_contents
|
3
|
+
|
4
|
+
def initialize(filename)
|
5
|
+
@filename = filename
|
6
|
+
|
7
|
+
path = File.expand_path(filename)
|
8
|
+
if File.exist?(path)
|
9
|
+
file = File.open(path, 'r')
|
10
|
+
else
|
11
|
+
raise "File does not exist." + path.inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
@file_contents = ""
|
15
|
+
|
16
|
+
if String.method_defined?(:encode)
|
17
|
+
@file_contents = file.read.encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
18
|
+
else
|
19
|
+
ic = Iconv.new('UTF-8', 'UTF-8')
|
20
|
+
file.each do |l|
|
21
|
+
begin
|
22
|
+
@file_contents += ic.iconv(l) + "\n"
|
23
|
+
rescue
|
24
|
+
puts "Encoding error: #{l}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def timestamps?
|
31
|
+
starts_with_timestamp?(raw_lines.first)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.timestamps?(filename)
|
35
|
+
reader = HistoryReader.new(filename)
|
36
|
+
reader.timestamps?
|
37
|
+
end
|
38
|
+
|
39
|
+
def shell_commands
|
40
|
+
raw_lines
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.files
|
44
|
+
possible_files.map{|f| File.expand_path(f) }.select{|f| File.exist?(f) }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def self.possible_files
|
50
|
+
zshfiles = ['~/.zsh_history', '~/.zshhistory', '~/.zhistory']
|
51
|
+
bashfiles = ['~/.bashhistory', '~/.bash_history']
|
52
|
+
shfiles = ['~/.shistory']
|
53
|
+
hfiles = ['~/.history']
|
54
|
+
|
55
|
+
files = (zshfiles + bashfiles + shfiles + hfiles).flatten
|
56
|
+
end
|
57
|
+
|
58
|
+
def raw_lines
|
59
|
+
file_contents.split("\n")
|
60
|
+
end
|
61
|
+
|
62
|
+
def starts_with_timestamp?(line)
|
63
|
+
line.initial == ":"
|
64
|
+
end
|
65
|
+
end
|
@@ -1,44 +1,14 @@
|
|
1
1
|
require 'iconv' unless String.method_defined?(:encode)
|
2
2
|
|
3
|
-
class OhMyZshReader
|
3
|
+
class OhMyZshReader < HistoryReader
|
4
4
|
attr_accessor :file_name, :file_contents
|
5
5
|
|
6
|
-
def initialize(file_name)
|
7
|
-
@file_name = file_name
|
8
|
-
|
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
|
15
|
-
|
16
|
-
@file_contents = ""
|
17
|
-
|
18
|
-
if String.method_defined?(:encode)
|
19
|
-
@file_contents = file.read.encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
20
|
-
else
|
21
|
-
ic = Iconv.new('UTF-8', 'UTF-8')
|
22
|
-
file.each do |l|
|
23
|
-
begin
|
24
|
-
@file_contents += ic.iconv(l) + "\n"
|
25
|
-
rescue
|
26
|
-
puts "Encoding error: #{l}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
6
|
def shell_commands
|
33
7
|
filtered_lines.map {|l| l.split(";").last.strip }
|
34
8
|
end
|
35
9
|
|
36
10
|
private
|
37
11
|
|
38
|
-
def raw_lines
|
39
|
-
file_contents.split("\n")
|
40
|
-
end
|
41
|
-
|
42
12
|
def filtered_lines
|
43
13
|
raw_lines.select{|l| valid_line?(l) }
|
44
14
|
end
|
data/lib/tree/word_tree_node.rb
CHANGED
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.
|
4
|
+
version: 0.0.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
16
|
-
requirement: &
|
16
|
+
requirement: &70275366759860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70275366759860
|
25
25
|
description: A parser and recommendation system for your shell aliases based on your
|
26
26
|
shell history
|
27
27
|
email: paul.mckellar@gmail.com
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/command/command_suggestor.rb
|
35
35
|
- lib/command/command_word.rb
|
36
36
|
- lib/huffshell.rb
|
37
|
+
- lib/readers/history_reader.rb
|
37
38
|
- lib/readers/oh_my_zsh_reader.rb
|
38
39
|
- lib/shell/alias_checker.rb
|
39
40
|
- lib/shell/alias_line.rb
|