realiaser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +22 -0
- data/Rakefile +6 -0
- data/Readme.md +65 -0
- data/Realiaser-0.0.1.gem +0 -0
- data/bin/realiaser +23 -0
- data/lib/alias_line.rb +27 -0
- data/lib/alias_suggestor.rb +20 -0
- data/lib/command_success_counter.rb +124 -0
- metadata +56 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
Realiaser (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
multi_json (1.3.7)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rspec (2.12.0)
|
13
|
+
rspec-core (~> 2.12.0)
|
14
|
+
rspec-expectations (~> 2.12.0)
|
15
|
+
rspec-mocks (~> 2.12.0)
|
16
|
+
rspec-core (2.12.0)
|
17
|
+
rspec-expectations (2.12.0)
|
18
|
+
diff-lcs (~> 1.1.3)
|
19
|
+
rspec-mocks (2.12.0)
|
20
|
+
simplecov (0.7.1)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
simplecov-html (~> 0.7.1)
|
23
|
+
simplecov-html (0.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
Realiaser!
|
30
|
+
rake
|
31
|
+
rspec
|
32
|
+
simplecov
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Paul McKellar
|
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/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
Realiaser
|
2
|
+
====================
|
3
|
+
|
4
|
+
Realiaser is a game which helps you memorize your shell aliases.
|
5
|
+
|
6
|
+
If you are like me, you have a lot of shell aliases but don't want to spend much time memorizing them. This gem helps remind you that you have defined an alias by telling you everytime you write a command where you should have used an alias.
|
7
|
+
|
8
|
+
I defined the point system to work as follows. +1 pt for every command executed which was executed properly. -50 for every time I forget to use an alias.
|
9
|
+
|
10
|
+
This is a pretty small library, only a two hour hack, but I've already started using more of my aliases because of the positive feedback loop it provides.
|
11
|
+
|
12
|
+
Features
|
13
|
+
---------------------
|
14
|
+
|
15
|
+
* Tells if you your last command should have used an alias.
|
16
|
+
* Keeps track of your score.
|
17
|
+
* Keeps track of your last successful command and unsuccessful command.
|
18
|
+
* Doesn't modify your ENV in any way.
|
19
|
+
|
20
|
+
Installation
|
21
|
+
---------------------
|
22
|
+
|
23
|
+
There are two parts to the installation. The library and integrating it with your shell.
|
24
|
+
|
25
|
+
```script
|
26
|
+
# install the gem (sudo is optional)
|
27
|
+
sudo gem install realiaser
|
28
|
+
|
29
|
+
# the ruby script needs to be able to access aliases defined in the shell conf
|
30
|
+
alias > ~/.alias.cache
|
31
|
+
```
|
32
|
+
|
33
|
+
This is the hard part. You need to change your right shell prompt.
|
34
|
+
|
35
|
+
```
|
36
|
+
function last_command() {
|
37
|
+
echo `history -1 | cut -d ' ' -f 3-20 | realiaser`
|
38
|
+
}
|
39
|
+
|
40
|
+
RPROMPT='%{$fg[$NCOLOR]%}%p $(last_command)%{$reset_color%}'
|
41
|
+
````
|
42
|
+
|
43
|
+
I have new aliases and it doesn't notice them.
|
44
|
+
---------------------
|
45
|
+
|
46
|
+
The ruby script can't see aliases in the environment.
|
47
|
+
|
48
|
+
```script
|
49
|
+
alias > ~/.alias.cache
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
Update
|
54
|
+
---------------------
|
55
|
+
|
56
|
+
```script
|
57
|
+
gem update realiaser
|
58
|
+
````
|
59
|
+
|
60
|
+
Questions
|
61
|
+
---------------------
|
62
|
+
|
63
|
+
Q: Isn't this going to slow down my CLI?
|
64
|
+
|
65
|
+
A: Running Ruby on every command isn't ideal, but it turns out that it didn't slow me down at all.
|
data/Realiaser-0.0.1.gem
ADDED
File without changes
|
data/bin/realiaser
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
directory_name = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require File.join(directory_name, '../lib/alias_line.rb')
|
4
|
+
require File.join(directory_name, '../lib/alias_suggestor.rb')
|
5
|
+
require File.join(directory_name, '../lib/command_success_counter.rb')
|
6
|
+
|
7
|
+
csc = Realiased::CommandSuccessCounter.new
|
8
|
+
|
9
|
+
path = File.expand_path("~/.alias.cache")
|
10
|
+
suggestor = Realiased::AliasSuggestor.new(path)
|
11
|
+
|
12
|
+
input = ARGF.read.strip
|
13
|
+
suggested = suggestor.suggest(input)
|
14
|
+
|
15
|
+
if suggested.nil?
|
16
|
+
csc.correct!(input)
|
17
|
+
csc.append_command(input, true)
|
18
|
+
puts "#{csc.score}"
|
19
|
+
else
|
20
|
+
csc.mistake!(input)
|
21
|
+
csc.append_command(input, false)
|
22
|
+
puts "#{suggested} (#{csc.score})"
|
23
|
+
end
|
data/lib/alias_line.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Realiased
|
2
|
+
class AliasLine
|
3
|
+
|
4
|
+
attr_accessor :shell_alias, :shell_command, :alias_line
|
5
|
+
|
6
|
+
def initialize(alias_line)
|
7
|
+
@alias_line = alias_line
|
8
|
+
splits = @alias_line.split('=')
|
9
|
+
@shell_command = splits.first.strip
|
10
|
+
@shell_alias = splits.last.strip.gsub("'",'')
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
!nocorrect? && !transpose?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def transpose?
|
20
|
+
["ls"].include?(@shell_alias)
|
21
|
+
end
|
22
|
+
|
23
|
+
def nocorrect?
|
24
|
+
@alias_line.scan("nocorrect") != []
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Realiased
|
2
|
+
|
3
|
+
class AliasSuggestor
|
4
|
+
attr_accessor :alias_lines
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@alias_lines = {}
|
8
|
+
File.new(path,'r').each do |line|
|
9
|
+
alias_line = AliasLine.new(line)
|
10
|
+
next unless alias_line.valid?
|
11
|
+
@alias_lines[alias_line.shell_alias] = alias_line.shell_command
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def suggest(command)
|
16
|
+
@alias_lines[command]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Realiased
|
2
|
+
|
3
|
+
class CommandSuccessCounter
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
@@default_file_location = "~/.realiaser_success_metrics"
|
9
|
+
@@history_file = "~/.realiaser_history"
|
10
|
+
|
11
|
+
@@positive_points = 1
|
12
|
+
@@negative_points = 50
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
if !file_exists?
|
16
|
+
@data = {}
|
17
|
+
self.write
|
18
|
+
else
|
19
|
+
self.load
|
20
|
+
end
|
21
|
+
set_defaults!
|
22
|
+
end
|
23
|
+
|
24
|
+
def score
|
25
|
+
@data[:score]
|
26
|
+
end
|
27
|
+
|
28
|
+
def high_score
|
29
|
+
@data[:high_score]
|
30
|
+
end
|
31
|
+
|
32
|
+
def high_score_at
|
33
|
+
@data[:high_score_at]
|
34
|
+
end
|
35
|
+
|
36
|
+
def data
|
37
|
+
@data
|
38
|
+
end
|
39
|
+
|
40
|
+
def correct!(last_line)
|
41
|
+
if @data[:last_line] != last_line
|
42
|
+
@data[:last_line] = last_line
|
43
|
+
@data[:score] = @data[:score] + @@positive_points
|
44
|
+
mark_high_score
|
45
|
+
self.write
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def mistake!(last_line)
|
50
|
+
if @data[:last_line] != last_line
|
51
|
+
@data[:last_line] = last_line
|
52
|
+
@data[:mistaken_command] = last_line
|
53
|
+
@data[:score] = [@data[:score] - @@negative_points, 0].max
|
54
|
+
self.write
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def append_command(command, increment)
|
59
|
+
if increment
|
60
|
+
history_file << "#{command}:#{@@positive_points}:#{score}\n"
|
61
|
+
else
|
62
|
+
history_file << "#{command}:#{@@negative_points}:#{score}\n"
|
63
|
+
end
|
64
|
+
history_file.close
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def mark_high_score
|
70
|
+
return unless high_score?
|
71
|
+
@data[:high_score] = score
|
72
|
+
@data[:high_score_at] = Time.now
|
73
|
+
end
|
74
|
+
|
75
|
+
def high_score?
|
76
|
+
score > high_score
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_defaults!
|
80
|
+
@data[:score] ||= 0
|
81
|
+
@data[:high_score] ||= 0
|
82
|
+
@data[:high_score_at] ||= Time.now
|
83
|
+
end
|
84
|
+
|
85
|
+
def history_file
|
86
|
+
File.new(history_path, 'a')
|
87
|
+
end
|
88
|
+
|
89
|
+
def load
|
90
|
+
@data = YAML.load(File.new(path, 'r').read)
|
91
|
+
unless @data.instance_of?(Hash)
|
92
|
+
@data = {}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def write
|
97
|
+
file = File.new(path, 'w')
|
98
|
+
file << @data.to_yaml
|
99
|
+
file.close
|
100
|
+
end
|
101
|
+
|
102
|
+
def history_path
|
103
|
+
File.expand_path(@@history_file)
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.path
|
107
|
+
File.expand_path(@@default_file_location)
|
108
|
+
end
|
109
|
+
|
110
|
+
def path
|
111
|
+
self.class.path
|
112
|
+
end
|
113
|
+
|
114
|
+
def touch
|
115
|
+
FileUtils.touch(path)
|
116
|
+
end
|
117
|
+
|
118
|
+
def file_exists?
|
119
|
+
File.exists?(path)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: realiaser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paul McKellar
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Adds a feedback look and gamifies your shell usage to help you learn
|
15
|
+
your aliases.
|
16
|
+
email: paul.mckellar@gmail.com
|
17
|
+
executables:
|
18
|
+
- realiaser
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/alias_line.rb
|
23
|
+
- lib/alias_suggestor.rb
|
24
|
+
- lib/command_success_counter.rb
|
25
|
+
- bin/realiaser
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE
|
29
|
+
- Rakefile
|
30
|
+
- Readme.md
|
31
|
+
- Realiaser-0.0.1.gem
|
32
|
+
homepage: https://github.com/paulmars/realiaser
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.10
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Realiaser is a game which helps you memorize your shell aliases.
|
56
|
+
test_files: []
|