aliasing 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +53 -0
- data/bin/aliasing +5 -0
- data/lib/aliasing.rb +24 -0
- data/lib/aliasing/cli.rb +21 -0
- data/lib/aliasing/history.rb +28 -0
- data/lib/aliasing/version.rb +3 -0
- metadata +104 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Max Lahey
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
### Aliasing
|
2
|
+
|
3
|
+
A little test project to get familiar with creating Ruby CLIs using Thor. It exists to facilitate making aliases for commonly used bash commands.
|
4
|
+
|
5
|
+
#### Installation
|
6
|
+
|
7
|
+
$ gem install aliasing
|
8
|
+
|
9
|
+
#### Usage
|
10
|
+
|
11
|
+
**Find most frequently used bash commands**
|
12
|
+
|
13
|
+
$ aliasing most_frequent {history file} {num entries}
|
14
|
+
|
15
|
+
-> num entries defaults to 10
|
16
|
+
|
17
|
+
Example
|
18
|
+
|
19
|
+
$ aliasing most_frequent ~/.bash_history 15
|
20
|
+
|
21
|
+
will return most frequently used commands from the current users .bash_history file
|
22
|
+
|
23
|
+
**Make an alias**
|
24
|
+
|
25
|
+
(Right, because its so *hard* to do by yourself...)
|
26
|
+
|
27
|
+
$ aliasing make_alias {alias name} {command} {location = ~/.bash_profile}
|
28
|
+
|
29
|
+
-> location defaults to ~/.bash_profile unless otherwise specified
|
30
|
+
|
31
|
+
Example
|
32
|
+
|
33
|
+
$ aliasing make_alias ll "ls -l"
|
34
|
+
|
35
|
+
Aliasing will refuse to create an alias for one that an alias name that already exists.
|
36
|
+
|
37
|
+
NB: be sure to use quotes for multi-word commands
|
38
|
+
|
39
|
+
### Todos (if this project actually had legs)
|
40
|
+
|
41
|
+
- write rspecs
|
42
|
+
- write cucumber tests for CLI
|
43
|
+
- more tools for alias management
|
44
|
+
- removing an alias by name
|
45
|
+
- making suggestions (eg. "bundle exec rake db:migrate" -> "rmigrate", "ssh -i ~/.ssh/mykey.pem" -> "sshmykey")
|
46
|
+
|
47
|
+
#### Version History
|
48
|
+
|
49
|
+
`0.0.1` - Added commands to find the most frequently used bash commands and create aliases in a target file.
|
50
|
+
|
51
|
+
#### License
|
52
|
+
|
53
|
+
MIT
|
data/bin/aliasing
ADDED
data/lib/aliasing.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'aliasing/version'
|
2
|
+
require 'aliasing/history'
|
3
|
+
require 'aliasing/cli'
|
4
|
+
|
5
|
+
module Aliasing
|
6
|
+
class << self
|
7
|
+
def make_alias(name, command, location)
|
8
|
+
existing_alias = verify_uniqueness_of name
|
9
|
+
return puts "Error: #{name} is already a bash alias name for #{existing_alias}" if existing_alias
|
10
|
+
|
11
|
+
%x[echo 'alias #{name}="#{command}"' >> #{location}]
|
12
|
+
end
|
13
|
+
|
14
|
+
def verify_uniqueness_of(alias_name)
|
15
|
+
alias_list = %x[source ~/.profile && source ~/.bash_profile && alias].split "\n"
|
16
|
+
aliases = {}
|
17
|
+
alias_list.each { |a|
|
18
|
+
match = a.match(/(.*)=(.*)/)
|
19
|
+
aliases[match[1]] = match[2]
|
20
|
+
}
|
21
|
+
return aliases[alias_name]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/aliasing/cli.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Aliasing
|
4
|
+
class CLI < Thor
|
5
|
+
|
6
|
+
desc "most_frequent", "Get list of most frequently used bash commands"
|
7
|
+
def most_frequent(history_file, num = 10)
|
8
|
+
f = File.new(history_file)
|
9
|
+
history = f.read.split "\n"
|
10
|
+
History.new(history).most_frequent(num.to_i).each{ |k, v|
|
11
|
+
puts "'#{k}' - #{v}"
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "make_alias", "Make and export an alias to your profile - defaults to ~/.bash_profile"
|
16
|
+
def make_alias(name, command, location = "~/.bash_profile")
|
17
|
+
Aliasing.make_alias name, command, location
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Aliasing
|
2
|
+
class History
|
3
|
+
|
4
|
+
attr_accessor :entries, :by_frequency
|
5
|
+
|
6
|
+
def initialize(entries)
|
7
|
+
@entries = entries
|
8
|
+
@by_frequency = {}
|
9
|
+
sort_by_frequency
|
10
|
+
end
|
11
|
+
|
12
|
+
def sort_by_frequency
|
13
|
+
entries_with_freqency = {}
|
14
|
+
|
15
|
+
@entries.each { |e|
|
16
|
+
entries_with_freqency[e] ||= 0
|
17
|
+
entries_with_freqency[e] += 1
|
18
|
+
}
|
19
|
+
|
20
|
+
@by_frequency = entries_with_freqency.sort_by{|k,v| v}.reverse
|
21
|
+
end
|
22
|
+
|
23
|
+
def most_frequent(num)
|
24
|
+
Hash[@by_frequency[0..num-1]]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aliasing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Max Lahey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.18.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.18.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.14'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
description: Aliasing makes recommendations of potential aliases based on your bash
|
63
|
+
history
|
64
|
+
email:
|
65
|
+
- maxwellslahey@gmail.com
|
66
|
+
executables:
|
67
|
+
- aliasing
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- bin/aliasing
|
72
|
+
- lib/aliasing/cli.rb
|
73
|
+
- lib/aliasing/history.rb
|
74
|
+
- lib/aliasing/version.rb
|
75
|
+
- lib/aliasing.rb
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
homepage: https://github.com/maxwells/aliasing
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.9.3
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.25
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Bash alias suggestion tool
|
103
|
+
test_files: []
|
104
|
+
has_rdoc:
|