hsume2-aka 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ Feature: Upgrade aka
2
+ In order to keep the aka configuration up to date
3
+ I want to upgrade the configuration from the command-line
4
+ So I don't have to do it manually
5
+
6
+ Background:
7
+ Given I set the AKA environment variable to the ".aka.yml" file in the working directory
8
+ And I set the environment variables to:
9
+ | variable | value |
10
+ | NO_MAN | 1 |
11
+
12
+
13
+ Scenario: Upgrade from v0 to v1
14
+ Given a file named ".aka.yml" with:
15
+ """
16
+ ---
17
+ 1: !ruby/object:OpenStruct
18
+ table:
19
+ :shortcut: ls
20
+ :command: ls -F --color=auto
21
+ modifiable: true
22
+
23
+ """
24
+ When I run `aka upgrade`
25
+ Then the exit status should be 0
26
+ And the file ".aka.yml" should contain exactly:
27
+ """
28
+ ---
29
+ :version: '1'
30
+ :shortcuts:
31
+ 1: !ruby/object:OpenStruct
32
+ table:
33
+ :shortcut: ls
34
+ :command: ls -F --color=auto
35
+ modifiable: true
36
+
37
+ """
38
+ And the stdout should contain "Upgraded"
39
+ And the stdout should contain ".aka.yml"
40
+ And the stdout should contain "Backed up to"
41
+ And the stdout should contain ".aka.yml.backup"
42
+ And the file ".aka.yml.backup" should contain exactly:
43
+ """
44
+ ---
45
+ 1: !ruby/object:OpenStruct
46
+ table:
47
+ :shortcut: ls
48
+ :command: ls -F --color=auto
49
+ modifiable: true
50
+
51
+ """
data/lib/aka/app.rb CHANGED
@@ -43,6 +43,12 @@ module Aka
43
43
  store.edit(options)
44
44
  when 'show'
45
45
  store.show(options)
46
+ when 'link'
47
+ store.link(options)
48
+ when 'upgrade'
49
+ store.upgrade(options)
50
+ when 'sync'
51
+ store.sync
46
52
  else
47
53
  store.help(command, options)
48
54
  end
@@ -60,6 +66,7 @@ module Aka
60
66
  on("-i FILE", "--input")
61
67
  on("-h", "--help")
62
68
  on("-v", "--version")
69
+ on("--delete")
63
70
 
64
71
  use_log_level_option
65
72
  end
@@ -0,0 +1,92 @@
1
+ module Aka
2
+ class Configuration
3
+ FORMAT = '1'
4
+
5
+ attr_reader :configuration
6
+
7
+ module Shortcut
8
+ def self.parse(options)
9
+ OpenStruct.new.tap do |row|
10
+ row.shortcut = options['shortcut']
11
+ row.command = options['command']
12
+ row.tag = options['tag'] if options['tag']
13
+ row.description = options['description'] if options['description']
14
+ row.function = options['function'] if options['function']
15
+ end
16
+ end
17
+
18
+ def self.generate_output(row)
19
+ string = if row.function
20
+ <<-EOS.gsub(/^ /, '')
21
+ function #{row.shortcut} {
22
+ #{row.command}
23
+ }
24
+ EOS
25
+ else
26
+ %{alias #{row.shortcut}="#{row.command.gsub(%{"}, %{\\"})}"}
27
+ end
28
+
29
+ string
30
+ end
31
+ end
32
+
33
+ module Link
34
+ def self.parse(options)
35
+ unless options['tag'] && options['output']
36
+ abort("Invalid link.")
37
+ end
38
+
39
+ OpenStruct.new.tap do |row|
40
+ row.tag = options['tag'] if options['tag']
41
+ row.output = options['output'] if options['output']
42
+ end
43
+ end
44
+ end
45
+
46
+ def initialize
47
+ @configuration ||= begin
48
+ if File.exist?(aka_yml)
49
+ YAML::load_file(aka_yml)
50
+ else
51
+ {}
52
+ end
53
+ end
54
+ @configuration[:shortcuts] ||= {}
55
+ end
56
+
57
+ def shortcuts
58
+ @shortcuts ||= Shortcuts.new(@configuration[:shortcuts])
59
+ end
60
+
61
+ def version
62
+ @configuration[:version]
63
+ end
64
+
65
+ def save
66
+ current = {
67
+ :version => version || FORMAT,
68
+ :shortcuts => shortcuts.all
69
+ }
70
+
71
+ current[:links] = links.all if links.any?
72
+
73
+ File.open(aka_yml, 'w+') do |f|
74
+ f.write current.to_yaml
75
+ end
76
+ end
77
+
78
+ def links
79
+ @links ||= Links.new(@configuration[:links] || [])
80
+ end
81
+
82
+ def upgrade
83
+ if !version
84
+ Upgrader::FromV0.run(aka_yml)
85
+ end
86
+ end
87
+
88
+ def aka_yml
89
+ ENV['AKA'] || File.expand_path('~/.aka.yml')
90
+ end
91
+ end
92
+ end
data/lib/aka/links.rb ADDED
@@ -0,0 +1,29 @@
1
+ module Aka
2
+ class Links
3
+ def initialize(links)
4
+ @links = links.dup
5
+ end
6
+
7
+ def add(link)
8
+ link = Configuration::Link.parse(link)
9
+ @links << link unless @links.include?(link)
10
+ end
11
+
12
+ def delete(link)
13
+ link = Configuration::Link.parse(link)
14
+ @links.delete(link)
15
+ end
16
+
17
+ def any?
18
+ @links.any?
19
+ end
20
+
21
+ def all
22
+ @links.dup
23
+ end
24
+
25
+ def each(&blk)
26
+ @links.each(&blk)
27
+ end
28
+ end
29
+ end
File without changes
@@ -0,0 +1,61 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "AKA\-LINK" "1" "March 2014" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBaka\-link\fR \- Link keyboard shortcuts
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBaka link\fR [\fB\-t\fR \fItag1\fR[,\fItag2\fR\.\.\.]] [\fB\-o\fR \fIoutput\fR] [\fB\-\-delete\fR]
11
+ .
12
+ .SH "DESCRIPTION"
13
+ This command manages keyboard shortcuts links in \fBaka(7)\fR\.
14
+ .
15
+ .P
16
+ After creating a link, you can easily synchronize changes to shortcuts to designated \fBoutput\fR files\.
17
+ .
18
+ .SH "OPTIONS"
19
+ .
20
+ .TP
21
+ \fB\-t\fR \fItag1\fR[,\fItag2\fR\.\.\.]
22
+ A comma\-separated list of tags to filter with\. Shortcuts tagged with \fItag1\fR[,\fItag2\fR\.\.\.] will be included\. Shortcuts tagged with other tags are excluded\. Shortcuts with no tags are always included\.
23
+ .
24
+ .TP
25
+ \fB\-o <output>\fR
26
+ The location to link the output to\.
27
+ .
28
+ .TP
29
+ \fB\-\-delete\fR
30
+ Delete the link with the given options\.
31
+ .
32
+ .SH "EXAMPLES"
33
+ Add a link:
34
+ .
35
+ .IP "" 4
36
+ .
37
+ .nf
38
+
39
+ $ aka link \-\-tag os:linux \-\-output ~/\.aka\.zsh
40
+ Saved link\.
41
+ .
42
+ .fi
43
+ .
44
+ .IP "" 0
45
+ .
46
+ .P
47
+ Remove a link:
48
+ .
49
+ .IP "" 4
50
+ .
51
+ .nf
52
+
53
+ $ aka link \-\-delete \-\-tag os:linux \-\-output ~/\.aka\.zsh
54
+ Removed link\.
55
+ .
56
+ .fi
57
+ .
58
+ .IP "" 0
59
+ .
60
+ .SH "SEE ALSO"
61
+ \fBaka(7)\fR, \fBaka\-sync(1)\fR
@@ -0,0 +1,54 @@
1
+ AKA-LINK(1) AKA-LINK(1)
2
+
3
+
4
+
5
+ NAME
6
+ aka-link - Link keyboard shortcuts
7
+
8
+ SYNOPSIS
9
+ aka link [-t tag1[,tag2...]] [-o output] [--delete]
10
+
11
+ DESCRIPTION
12
+ This command manages keyboard shortcuts links in aka(7).
13
+
14
+ After creating a link, you can easily synchronize changes to shortcuts
15
+ to designated output files.
16
+
17
+ OPTIONS
18
+ -t tag1[,tag2...]
19
+ A comma-separated list of tags to filter with. Shortcuts tagged
20
+ with tag1[,tag2...] will be included. Shortcuts tagged with
21
+ other tags are excluded. Shortcuts with no tags are always
22
+ included.
23
+
24
+ -o <output>
25
+ The location to link the output to.
26
+
27
+ --delete
28
+ Delete the link with the given options.
29
+
30
+ EXAMPLES
31
+ Add a link:
32
+
33
+
34
+
35
+ $ aka link --tag os:linux --output ~/.aka.zsh
36
+ Saved link.
37
+
38
+
39
+
40
+ Remove a link:
41
+
42
+
43
+
44
+ $ aka link --delete --tag os:linux --output ~/.aka.zsh
45
+ Removed link.
46
+
47
+
48
+
49
+ SEE ALSO
50
+ aka(7), aka-sync(1)
51
+
52
+
53
+
54
+ March 2014 AKA-LINK(1)
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "AKA\-LIST" "1" "February 2014" "" ""
4
+ .TH "AKA\-LIST" "1" "March 2014" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBaka\-list\fR \- List keyboard shortcuts
@@ -60,4 +60,4 @@ SEE ALSO
60
60
 
61
61
 
62
62
 
63
- February 2014 AKA-LIST(1)
63
+ March 2014 AKA-LIST(1)
@@ -0,0 +1,36 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "AKA\-SYNC" "1" "March 2014" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBaka\-sync\fR \- Synchronize keyboard shortcuts
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBaka sync\fR
11
+ .
12
+ .SH "DESCRIPTION"
13
+ This command manages synchronizes keyboard shortcuts links in \fBaka(7)\fR\.
14
+ .
15
+ .P
16
+ Any links you\'ve created will be generated to the designated \fBoutput\fR with the given \fBtags\fR\.
17
+ .
18
+ .SH "EXAMPLES"
19
+ Synchronize links:
20
+ .
21
+ .IP "" 4
22
+ .
23
+ .nf
24
+
25
+ $ aka link \-\-tag os:linux \-\-output ~/\.aka\.zsh
26
+ Saved link\.
27
+ $ aka sync
28
+ Generated ~/\.aka\.zsh\.
29
+ 4 shortcut(s) excluded (#linux)\.
30
+ .
31
+ .fi
32
+ .
33
+ .IP "" 0
34
+ .
35
+ .SH "SEE ALSO"
36
+ \fBaka(7)\fR, \fBaka\-link(1)\fR
@@ -0,0 +1,35 @@
1
+ AKA-SYNC(1) AKA-SYNC(1)
2
+
3
+
4
+
5
+ NAME
6
+ aka-sync - Synchronize keyboard shortcuts
7
+
8
+ SYNOPSIS
9
+ aka sync
10
+
11
+ DESCRIPTION
12
+ This command manages synchronizes keyboard shortcuts links in aka(7).
13
+
14
+ Any links you've created will be generated to the designated output
15
+ with the given tags.
16
+
17
+ EXAMPLES
18
+ Synchronize links:
19
+
20
+
21
+
22
+ $ aka link --tag os:linux --output ~/.aka.zsh
23
+ Saved link.
24
+ $ aka sync
25
+ Generated ~/.aka.zsh.
26
+ 4 shortcut(s) excluded (#linux).
27
+
28
+
29
+
30
+ SEE ALSO
31
+ aka(7), aka-link(1)
32
+
33
+
34
+
35
+ March 2014 AKA-SYNC(1)
@@ -0,0 +1,31 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "AKA\-UPGRADE" "1" "March 2014" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBaka\-upgrade\fR \- Upgrade keyboard shortcuts
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBaka upgrade\fR
11
+ .
12
+ .SH "DESCRIPTION"
13
+ This command manages upgrades the keyboard shortcuts format in \fBaka(7)\fR\.
14
+ .
15
+ .SH "EXAMPLES"
16
+ Upgrade links from v0 to v1:
17
+ .
18
+ .IP "" 4
19
+ .
20
+ .nf
21
+
22
+ $ aka upgrade
23
+ Upgraded ~/\.aka\.yml\.
24
+ Backed up to ~/\.aka\.yml\.backup\."
25
+ .
26
+ .fi
27
+ .
28
+ .IP "" 0
29
+ .
30
+ .SH "SEE ALSO"
31
+ \fBaka(7)\fR
@@ -0,0 +1,30 @@
1
+ AKA-UPGRADE(1) AKA-UPGRADE(1)
2
+
3
+
4
+
5
+ NAME
6
+ aka-upgrade - Upgrade keyboard shortcuts
7
+
8
+ SYNOPSIS
9
+ aka upgrade
10
+
11
+ DESCRIPTION
12
+ This command manages upgrades the keyboard shortcuts format in aka(7).
13
+
14
+ EXAMPLES
15
+ Upgrade links from v0 to v1:
16
+
17
+
18
+
19
+ $ aka upgrade
20
+ Upgraded ~/.aka.yml.
21
+ Backed up to ~/.aka.yml.backup."
22
+
23
+
24
+
25
+ SEE ALSO
26
+ aka(7)
27
+
28
+
29
+
30
+ March 2014 AKA-UPGRADE(1)
data/lib/aka/man/aka.7 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "AKA" "7" "February 2014" "" ""
4
+ .TH "AKA" "7" "March 2014" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBaka\fR \- Manage Shell Keyboard Shortcuts
@@ -22,8 +22,14 @@
22
22
  \fBaka\fR list [options]
23
23
  .
24
24
  .br
25
+ \fBaka\fR link [options]
26
+ .
27
+ .br
25
28
  \fBaka\fR generate [options]
26
29
  .
30
+ .br
31
+ \fBaka\fR sync
32
+ .
27
33
  .SH "DESCRIPTION"
28
34
  \fBaka\fR is an easy way to manage keyboard shortcuts in UNIX shells\.
29
35
  .
@@ -158,6 +164,66 @@ Removes shortcut\.
158
164
  .
159
165
  .IP "" 0
160
166
  .
167
+ .P
168
+ Add a link:
169
+ .
170
+ .IP "" 4
171
+ .
172
+ .nf
173
+
174
+ $ aka link \-\-tag os:linux \-\-output ~/\.aka\.zsh
175
+ Saved link\.
176
+ .
177
+ .fi
178
+ .
179
+ .IP "" 0
180
+ .
181
+ .P
182
+ Remove a link:
183
+ .
184
+ .IP "" 4
185
+ .
186
+ .nf
187
+
188
+ $ aka link \-\-delete \-\-tag os:linux \-\-output ~/\.aka\.zsh
189
+ Removed link\.
190
+ .
191
+ .fi
192
+ .
193
+ .IP "" 0
194
+ .
195
+ .P
196
+ Synchronize links:
197
+ .
198
+ .IP "" 4
199
+ .
200
+ .nf
201
+
202
+ $ aka link \-\-tag os:linux \-\-output ~/\.aka\.zsh
203
+ Saved link\.
204
+ $ aka sync
205
+ Generated ~/\.aka\.zsh\.
206
+ 4 shortcut(s) excluded (#linux)\.
207
+ .
208
+ .fi
209
+ .
210
+ .IP "" 0
211
+ .
212
+ .P
213
+ Upgrade links from v0 to v1:
214
+ .
215
+ .IP "" 4
216
+ .
217
+ .nf
218
+
219
+ $ aka upgrade
220
+ Upgraded ~/\.aka\.yml\.
221
+ Backed up to ~/\.aka\.yml\.backup\."
222
+ .
223
+ .fi
224
+ .
225
+ .IP "" 0
226
+ .
161
227
  .SH "ENVIRONMENT"
162
228
  .
163
229
  .TP
@@ -11,7 +11,9 @@ SYNOPSIS
11
11
  aka edit shortcut [options]
12
12
  aka remove shortcut
13
13
  aka list [options]
14
+ aka link [options]
14
15
  aka generate [options]
16
+ aka sync
15
17
 
16
18
  DESCRIPTION
17
19
  aka is an easy way to manage keyboard shortcuts in UNIX shells.
@@ -110,6 +112,46 @@ EXAMPLES
110
112
 
111
113
 
112
114
 
115
+ Add a link:
116
+
117
+
118
+
119
+ $ aka link --tag os:linux --output ~/.aka.zsh
120
+ Saved link.
121
+
122
+
123
+
124
+ Remove a link:
125
+
126
+
127
+
128
+ $ aka link --delete --tag os:linux --output ~/.aka.zsh
129
+ Removed link.
130
+
131
+
132
+
133
+ Synchronize links:
134
+
135
+
136
+
137
+ $ aka link --tag os:linux --output ~/.aka.zsh
138
+ Saved link.
139
+ $ aka sync
140
+ Generated ~/.aka.zsh.
141
+ 4 shortcut(s) excluded (#linux).
142
+
143
+
144
+
145
+ Upgrade links from v0 to v1:
146
+
147
+
148
+
149
+ $ aka upgrade
150
+ Upgraded ~/.aka.yml.
151
+ Backed up to ~/.aka.yml.backup."
152
+
153
+
154
+
113
155
  ENVIRONMENT
114
156
  AKA:
115
157
  The file where aka stores everything. Default: ~/.aka.yml
@@ -118,4 +160,4 @@ ENVIRONMENT
118
160
 
119
161
 
120
162
 
121
- February 2014 AKA(7)
163
+ March 2014 AKA(7)