aka 0.5.4 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/bin/aka +13 -6
- data/features/delete.feature +1 -1
- data/features/new_file.feature +18 -0
- data/features/step_definitions/aka_steps.rb +4 -0
- data/lib/aka/version.rb +1 -1
- data/lib/aka.rb +55 -5
- metadata +4 -3
- data/aka-0.5.2.gem +0 -0
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -50,7 +50,7 @@ I really like this app, but I've got other things I want to work on. But there a
|
|
50
50
|
|
51
51
|
1. Support for a config file that will let you use a file other than `~/.alias` for your aliases
|
52
52
|
1. Grouping aliases
|
53
|
-
1. Aliases sorted alphabetically by default.
|
53
|
+
1. Aliases sorted alphabetically by default. -**DONE!**
|
54
54
|
|
55
55
|
|
56
56
|
[David Copeland]:http://www.naildrivin5.com/
|
data/bin/aka
CHANGED
@@ -4,6 +4,7 @@ require 'optparse'
|
|
4
4
|
require 'methadone'
|
5
5
|
require 'aka'
|
6
6
|
require 'fileutils'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
class App
|
9
10
|
include Methadone::Main
|
@@ -11,13 +12,15 @@ class App
|
|
11
12
|
include Aka
|
12
13
|
|
13
14
|
main do |aliasString,value|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
|
16
|
+
al = AliasList.new options["alias-file"]
|
17
|
+
#options.each do |key, value|
|
18
|
+
# debug("#{key} : #{value}")
|
19
|
+
#end
|
18
20
|
al.backup if options[:backup]
|
19
21
|
al.list if options[:list]
|
20
22
|
al.showAll if options[:L]
|
23
|
+
al.change_defaults 'random', options[:D] if options[:D]
|
21
24
|
if options[:show]
|
22
25
|
if aliasString == nil
|
23
26
|
fatal("Needs an alias string to show the related command!")
|
@@ -44,7 +47,7 @@ class App
|
|
44
47
|
end
|
45
48
|
|
46
49
|
# supplemental methods here
|
47
|
-
|
50
|
+
|
48
51
|
# Declare command-line interface here
|
49
52
|
|
50
53
|
description "Manage your aliases without editing dot files."
|
@@ -55,7 +58,11 @@ class App
|
|
55
58
|
on("-s", "--show", "Show what the specified alias does")
|
56
59
|
on("-b", "--backup", "Create a backup copy of your alias file")
|
57
60
|
on("-d", "--delete", "Delete all keys from your alias file")
|
58
|
-
on("-L", "--list-all","Display all aliases and
|
61
|
+
on("-L", "--list-all","Display all aliases and commands.")
|
62
|
+
on("--alias-file FILENAME","Create and use a new alias file.")
|
63
|
+
#on("-D NEW", "Create a random default value for testing purposes.")
|
64
|
+
|
65
|
+
defaults_from_config_file '.aka'
|
59
66
|
|
60
67
|
arg :alias, :optional
|
61
68
|
arg :value, :optional
|
data/features/delete.feature
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: Use an alternate alias file
|
2
|
+
In order to fit my personal workflow better
|
3
|
+
I want to be able to use a file other than `~/.alias` to store my aliases
|
4
|
+
So that I can be large and in charge.
|
5
|
+
|
6
|
+
Scenario: Create a new alias file
|
7
|
+
When I run `aka --alias-file .shortcuts` interactively
|
8
|
+
And I type "y"
|
9
|
+
And I close the stdin stream
|
10
|
+
Then a file named "/tmp/akaTest/.shortcuts" should exist
|
11
|
+
And the file "/tmp/akaTest/.shortcuts" should contain "alias test"
|
12
|
+
|
13
|
+
Scenario: Check for a configuration file
|
14
|
+
When I run `aka --alias-file .newcuts` interactively
|
15
|
+
And I type "y"
|
16
|
+
And I close the stdin stream
|
17
|
+
Then a file named "/tmp/akaTest/.aka" should exist
|
18
|
+
And the file "/tmp/akaTest/.aka" should contain ".newcuts"
|
data/lib/aka/version.rb
CHANGED
data/lib/aka.rb
CHANGED
@@ -1,20 +1,33 @@
|
|
1
1
|
require "aka/version"
|
2
2
|
require "fileutils"
|
3
3
|
require "methadone"
|
4
|
+
require "yaml"
|
4
5
|
module Aka
|
5
6
|
|
6
7
|
class AliasList
|
7
8
|
include Methadone::CLILogging
|
8
9
|
|
9
|
-
def initialize
|
10
|
+
def initialize incoming_alias_file = nil
|
10
11
|
@aliasPattern = /alias (\S+)="(.+)"/
|
11
12
|
@aliases = {}
|
12
|
-
@
|
13
|
+
@defaults_file = "#{ENV["HOME"]}/.aka"
|
14
|
+
@defaults = get_defaults_from_file
|
15
|
+
debug "Incoming Alias file is #{incoming_alias_file}"
|
16
|
+
if incoming_alias_file
|
17
|
+
@fileName = "#{ENV["HOME"]}/#{incoming_alias_file}"
|
18
|
+
if incoming_alias_file != @defaults['alias-file']
|
19
|
+
change_alias_file incoming_alias_file
|
20
|
+
change_defaults "alias-file", incoming_alias_file
|
21
|
+
end
|
22
|
+
else
|
23
|
+
@fileName = "#{ENV["HOME"]}/.alias"
|
24
|
+
end
|
25
|
+
debug "The File we're looking at is #{@fileName}"
|
13
26
|
if !File.exists? @fileName
|
14
27
|
FileUtils.touch @fileName
|
15
28
|
end
|
16
|
-
debug ("made it to the class.
|
17
|
-
|
29
|
+
debug ("made it to the class. fileName is #{@fileName}, aliasPattern is #{@aliasPattern}.")
|
30
|
+
|
18
31
|
File.foreach(@fileName) do |line|
|
19
32
|
@aliasPattern.match(line)do |match|
|
20
33
|
#read them all into an array
|
@@ -82,5 +95,42 @@ module Aka
|
|
82
95
|
@aliases.sort.each { |key, value| filestring = filestring + "alias #{key}=\"#{value}\"\n" }
|
83
96
|
File.open(@fileName, "w") { |file| file.write filestring }
|
84
97
|
end
|
98
|
+
|
99
|
+
def change_alias_file new_file_name
|
100
|
+
new_file_name = "#{ENV['HOME']}/#{new_file_name}"
|
101
|
+
info "Copy current aliases into the new file?(Yna)"
|
102
|
+
copy = gets.chomp.downcase
|
103
|
+
|
104
|
+
if copy == "n"
|
105
|
+
FileUtils.touch(new_file_name)
|
106
|
+
@fileName = new_file_name
|
107
|
+
elsif copy == "a"
|
108
|
+
"creation of new aliases aborted!"
|
109
|
+
else
|
110
|
+
debug "Copying aliases from #{@defaults['alias-file']} to #{new_file_name}"
|
111
|
+
FileUtils.copy("#{ENV['HOME']}/#{@defaults['alias-file']}",new_file_name)
|
112
|
+
@fileName = new_file_name
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_defaults_from_file
|
117
|
+
if File.exists? @defaults_file
|
118
|
+
YAML::load(File.read(@defaults_file))
|
119
|
+
else
|
120
|
+
{'alias-file'=>".alias"}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def change_defaults name, value
|
125
|
+
if @defaults[name] == nil ||@defaults[name] != value
|
126
|
+
@defaults[name] = value
|
127
|
+
File.open(@defaults_file,"w"){|file| file.write @defaults.to_yaml}
|
128
|
+
info "Changed the default for #{name} to #{value}"
|
129
|
+
true
|
130
|
+
else
|
131
|
+
debug "No changes required!"
|
132
|
+
false
|
133
|
+
end
|
134
|
+
end
|
85
135
|
end
|
86
|
-
end
|
136
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- README.md
|
91
91
|
- README.rdoc
|
92
92
|
- Rakefile
|
93
|
-
- aka-0.5.2.gem
|
94
93
|
- aka.gemspec
|
95
94
|
- bin/aka
|
96
95
|
- features/add.feature
|
@@ -98,6 +97,7 @@ files:
|
|
98
97
|
- features/backup.feature
|
99
98
|
- features/delete.feature
|
100
99
|
- features/list.feature
|
100
|
+
- features/new_file.feature
|
101
101
|
- features/remove.feature
|
102
102
|
- features/show.feature
|
103
103
|
- features/step_definitions/aka_steps.rb
|
@@ -135,6 +135,7 @@ test_files:
|
|
135
135
|
- features/backup.feature
|
136
136
|
- features/delete.feature
|
137
137
|
- features/list.feature
|
138
|
+
- features/new_file.feature
|
138
139
|
- features/remove.feature
|
139
140
|
- features/show.feature
|
140
141
|
- features/step_definitions/aka_steps.rb
|
data/aka-0.5.2.gem
DELETED
Binary file
|