bundler_bash_completion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .bundle
3
+ .rbenv-version
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bundler_bash_completion (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rake (0.9.2.2)
11
+ rspec (2.9.0)
12
+ rspec-core (~> 2.9.0)
13
+ rspec-expectations (~> 2.9.0)
14
+ rspec-mocks (~> 2.9.0)
15
+ rspec-core (2.9.0)
16
+ rspec-expectations (2.9.0)
17
+ diff-lcs (~> 1.1.3)
18
+ rspec-mocks (2.9.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler_bash_completion!
25
+ rake (~> 0.9.2.2)
26
+ rspec (~> 2.9.0)
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Alexis Toulotte
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.mdown ADDED
@@ -0,0 +1,19 @@
1
+ # Bundler bash completion
2
+
3
+ Provides `bash` completion for [`bundle`](http://gembundler.com/) command.
4
+
5
+ ## Description
6
+
7
+ This will complete for all bundler commands (`install`, `outdated`, `show`,
8
+ etc.). Completion is also made for installed gems and their binaries (for
9
+ `bundle update`, `bundle exec`, etc.).
10
+
11
+ ## Installation
12
+
13
+ First, install gem:
14
+
15
+ gem install bundler_bash_completion
16
+
17
+ Then, add following line to your `~/.bashrc` file.
18
+
19
+ complete -C bundler_bash_completion -o default bundle
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc 'Default: runs specs.'
7
+ task :default => :spec
8
+
9
+ desc 'Run all specs in spec directory.'
10
+ RSpec::Core::RakeTask.new(:spec)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/bundler_bash_completion')
4
+
5
+ puts BundlerBashCompletion.new(ENV['COMP_LINE']).complete.sort.join("\n")
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'bundler_bash_completion'
3
+ s.version = File.read(File.expand_path(File.dirname(__FILE__) + '/VERSION')).strip
4
+ s.platform = Gem::Platform::RUBY
5
+ s.author = 'Alexis Toulotte'
6
+ s.email = 'al@alweb.org'
7
+ s.homepage = 'https://github.com/alexistoulotte/bundler_bash_completion'
8
+ s.summary = 'Bundler bash completion'
9
+ s.description = 'Provides bash completion for bundle command'
10
+
11
+ s.rubyforge_project = 'bundler_bash_completion'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_development_dependency 'rake', '~> 0.9.2.2'
19
+ s.add_development_dependency 'rspec', '~> 2.9.0'
20
+ end
@@ -0,0 +1,175 @@
1
+ class BundlerBashCompletion
2
+
3
+ TASKS = {
4
+ 'check' => {
5
+ '--gemfile' => :block,
6
+ '--no-color' => :continue,
7
+ '--path' => :block,
8
+ },
9
+ 'clean' => {
10
+ '--force' => :continue,
11
+ '--no-color' => :continue,
12
+ '--verbose' => :continue,
13
+ },
14
+ 'config' => {},
15
+ 'console' => {},
16
+ 'exec' => {
17
+ :bin => :continue,
18
+ },
19
+ 'gem' => {
20
+ '--bin' => :block,
21
+ },
22
+ 'help' => {
23
+ :task => :continue,
24
+ },
25
+ 'init' => {
26
+ '--no-color' => :continue,
27
+ '--verbose' => :continue,
28
+ },
29
+ 'install' => {
30
+ '--binstubs' => :continue,
31
+ '--deployment' => :continue,
32
+ '--gemfile' => :block,
33
+ '--local' => :continue,
34
+ '--no-color' => :continue,
35
+ '--path' => :block,
36
+ '--shebang' => :block,
37
+ '--standalone' => :block,
38
+ '--system' => :continue,
39
+ '--verbose' => :continue,
40
+ '--without' => :block,
41
+ },
42
+ 'list' => {
43
+ '--no-color' => :continue,
44
+ '--paths' => :continue,
45
+ '--verbose' => :continue,
46
+ :gem => :continue,
47
+ },
48
+ 'open' => {
49
+ :gem => :continue,
50
+ },
51
+ 'outdated' => {
52
+ '--local' => :continue,
53
+ '--no-color' => :continue,
54
+ '--pre' => :continue,
55
+ '--source' => :block,
56
+ '--verbose' => :continue,
57
+ :gem => :continue,
58
+ },
59
+ 'package' => {},
60
+ 'show' => {
61
+ '--no-color' => :continue,
62
+ '--paths' => :continue,
63
+ '--verbose' => :continue,
64
+ :gem => :continue,
65
+ },
66
+ 'update' => {
67
+ '--no-color' => :continue,
68
+ '--source' => :block,
69
+ '--verbose' => :continue,
70
+ :gems => :continue,
71
+ },
72
+ 'viz' => {
73
+ '--file' => :block,
74
+ '--format' => :block,
75
+ '--no-color' => :continue,
76
+ '--requirements' => :block,
77
+ '--verbose' => :continue,
78
+ '--version' => :block,
79
+ },
80
+ }
81
+
82
+ attr_reader :line
83
+
84
+ def initialize(line)
85
+ @line = line.to_s.gsub(/^\s+/, '').freeze
86
+ end
87
+
88
+ def arguments
89
+ @arguments ||= line.split(/\s+/)
90
+ end
91
+
92
+ def bins
93
+ @bins ||= begin
94
+ require 'bundler'
95
+ Bundler.setup.specs.map(&:executables).flatten + ['gem']
96
+ rescue Exception
97
+ ['gem']
98
+ end
99
+ end
100
+
101
+ def command
102
+ arguments.first.to_s
103
+ end
104
+
105
+ def completion_word
106
+ @completion_word ||= (line =~ /\s+$/) ? '' : arguments.last
107
+ end
108
+
109
+ def complete
110
+ return tasks_completion if tasks_completion?
111
+ return task_options_completion if task_options_completion?
112
+ []
113
+ end
114
+
115
+ def gems
116
+ @gems ||= begin
117
+ require 'bundler'
118
+ Bundler.setup.specs.map(&:name)
119
+ rescue Exception
120
+ []
121
+ end
122
+ end
123
+
124
+ def task
125
+ @task ||= (completion_step > 1) ? arguments[1].to_s : ''
126
+ end
127
+
128
+ def task_options
129
+ @task_options ||= (completion_step > 2) ? arguments[2..(completion_step - 1)] : []
130
+ end
131
+
132
+ private
133
+
134
+ def bundle_command?
135
+ command == 'bundle'
136
+ end
137
+
138
+ def completion_step
139
+ @completion_step ||= arguments.size - (completion_word.empty? ? 0 : 1)
140
+ end
141
+
142
+ def tasks_completion
143
+ TASKS.keys.select { |t| t.start_with?(completion_word) }
144
+ end
145
+
146
+ def tasks_completion?
147
+ bundle_command? && completion_step == 1
148
+ end
149
+
150
+ def task_options_completion
151
+ options = TASKS[task] || {}
152
+ return [] if options[task_options.last] == :block
153
+ completion = options.keys.map do |key|
154
+ if key == :task
155
+ (task_options & TASKS.keys).empty? ? TASKS.keys : nil
156
+ elsif key == :gem
157
+ (task_options & gems).empty? ? gems : nil
158
+ elsif key == :gems
159
+ gems - task_options
160
+ elsif key == :bin
161
+ (task_options & bins).empty? ? bins : nil
162
+ else
163
+ key
164
+ end
165
+ end
166
+ completion.flatten!
167
+ completion.compact!
168
+ completion.select { |c| c.start_with?(completion_word) }
169
+ end
170
+
171
+ def task_options_completion?
172
+ bundle_command? && completion_step > 1 && TASKS.key?(task)
173
+ end
174
+
175
+ end
@@ -0,0 +1,278 @@
1
+ require 'spec_helper'
2
+
3
+ describe BundlerBashCompletion do
4
+
5
+ def completion(line = nil)
6
+ BundlerBashCompletion.new(line)
7
+ end
8
+
9
+ describe '#arguments' do
10
+
11
+ it 'is given line splitted by whitespaces' do
12
+ completion('bundle exec rails s').arguments.should == ['bundle', 'exec', 'rails', 's']
13
+ end
14
+
15
+ end
16
+
17
+ describe '#bins' do
18
+
19
+ it 'is installed binaries' do
20
+ completion.bins.should include('autospec', 'bundler_bash_completion', 'gem', 'ldiff', 'rake', 'rspec')
21
+ completion.bins.should_not include('rails')
22
+ end
23
+
24
+ end
25
+
26
+ describe '#command' do
27
+
28
+ it 'is first argument' do
29
+ completion('bundle exec').command.should == 'bundle'
30
+ completion('rake').command.should == 'rake'
31
+ end
32
+
33
+ it 'is empty string if line is blank' do
34
+ completion(nil).command.should == ''
35
+ end
36
+
37
+ end
38
+
39
+ describe '#complete' do
40
+
41
+ context 'with "foo"' do
42
+
43
+ it 'is an empty array' do
44
+ completion('foo').complete.should == []
45
+ end
46
+
47
+ end
48
+
49
+ context 'with "bundle"' do
50
+
51
+ it 'is an empty array' do
52
+ completion('bundle').complete.should == []
53
+ end
54
+
55
+ end
56
+
57
+ context 'with "bundle "' do
58
+
59
+ it 'is all tasks' do
60
+ completion('bundle ').complete.should include('check', 'outdated', 'list', 'show')
61
+ end
62
+
63
+ end
64
+
65
+ context 'with "bundle "' do
66
+
67
+ it 'is all tasks' do
68
+ completion('bundle ').complete.should include('check', 'outdated', 'list', 'show')
69
+ end
70
+
71
+ end
72
+
73
+ context 'with "bundle in"' do
74
+
75
+ it 'is "init" & "install" tasks' do
76
+ completion('bundle in').complete.should == ['init', 'install']
77
+ end
78
+
79
+ end
80
+
81
+ context 'with "bundle in "' do
82
+
83
+ it 'is an empty array' do
84
+ completion('bundle in ').complete.should == []
85
+ end
86
+
87
+ end
88
+
89
+ context 'with "bundle foo"' do
90
+
91
+ it 'is an empty array' do
92
+ completion('bundle foo').complete.should == []
93
+ end
94
+
95
+ end
96
+
97
+ context 'with "bundle foo "' do
98
+
99
+ it 'is an empty array' do
100
+ completion('bundle foo ').complete.should == []
101
+ end
102
+
103
+ end
104
+
105
+ context 'with "bundle install "' do
106
+
107
+ it 'is "--local", "--path", "--verbose", "--without", etc.' do
108
+ completion('bundle install ').complete.should include('--local', '--path', '--verbose', '--without')
109
+ end
110
+
111
+ end
112
+
113
+ context 'with "bundle install --p"' do
114
+
115
+ it 'is "--path"' do
116
+ completion('bundle install --p').complete.should == ['--path']
117
+ end
118
+
119
+ end
120
+
121
+ context 'with "bundle install --path "' do
122
+
123
+ it 'is an empty array' do
124
+ completion('bundle install --path ').complete.should == []
125
+ end
126
+
127
+ end
128
+
129
+ context 'with "bundle install --local "' do
130
+
131
+ it 'is "--local", "--path", "--without", etc.' do
132
+ completion('bundle install ').complete.should include('--local', '--path', '--without')
133
+ end
134
+
135
+ end
136
+
137
+ context 'with "bundle help in"' do
138
+
139
+ it 'is "init" and "install"' do
140
+ completion('bundle help in').complete.should == ['init', 'install']
141
+ end
142
+
143
+ end
144
+
145
+ context 'with "bundle help install "' do
146
+
147
+ it 'is an empty array' do
148
+ completion('bundle help install ').complete.should == []
149
+ end
150
+
151
+ end
152
+
153
+ context 'with "bundle show "' do
154
+
155
+ it 'is gems and "--verbose", etc.' do
156
+ completion('bundle show ').complete.should include('diff-lcs', 'rake', 'rspec', '--verbose')
157
+ end
158
+
159
+ end
160
+
161
+ context 'with "bundle show rspec "' do
162
+
163
+ it 'is "--paths", "--no-color" and "--verbose"' do
164
+ completion('bundle show rspec ').complete.should == ['--no-color', '--paths', '--verbose']
165
+ end
166
+
167
+ end
168
+
169
+ context 'with "bundle update "' do
170
+
171
+ it 'is gems and "--verbose", etc.' do
172
+ completion('bundle update ').complete.should include('diff-lcs', 'rake', 'rspec', '--verbose')
173
+ end
174
+
175
+ end
176
+
177
+ context 'with "bundle update rake rspec "' do
178
+
179
+ it 'is gems (without rake & rspec) and "--verbose", etc.' do
180
+ completion('bundle update rake rspec ').complete.should include('bundler', 'diff-lcs', 'rspec-core', '--verbose')
181
+ completion('bundle update rake rspec ').complete.should_not include('rake', 'rspec')
182
+ end
183
+
184
+ end
185
+
186
+ context 'with "bundle exec "' do
187
+
188
+ it 'is bins' do
189
+ completion('bundle exec ').complete.should include('ldiff', 'rake', 'rspec')
190
+ completion('bundle exec ').complete.should_not include('--verbose')
191
+ end
192
+
193
+ end
194
+
195
+ context 'with "bundle exec rake "' do
196
+
197
+ it 'is an empty array' do
198
+ completion('bundle exec rake ').complete.should == []
199
+ end
200
+
201
+ end
202
+
203
+ end
204
+
205
+ describe '#completion_word' do
206
+
207
+ it 'is last word on line' do
208
+ completion('bundle instal').completion_word.should == 'instal'
209
+ end
210
+
211
+ it 'is an empty string if line ends with a white space' do
212
+ completion('bundle install ').completion_word.should == ''
213
+ completion('bundle install ').completion_word.should == ''
214
+ end
215
+
216
+ end
217
+
218
+ describe '#gems' do
219
+
220
+ it 'is installed gems' do
221
+ completion.gems.should include('bundler', 'rake', 'rspec', 'rspec-core', 'rspec-expectations')
222
+ completion.gems.should_not include('rails')
223
+ end
224
+
225
+ end
226
+
227
+ describe '#line' do
228
+
229
+ it 'is line given at initializion' do
230
+ completion('hello').line.should == 'hello'
231
+ end
232
+
233
+ it 'is frozen' do
234
+ expect {
235
+ completion('hello').line.gsub!('l', 'w')
236
+ }.to raise_error(/can't modify frozen String/)
237
+ end
238
+
239
+ it 'is converted to string' do
240
+ completion(:hello).line.should == 'hello'
241
+ end
242
+
243
+ it 'first whitespaces are removed' do
244
+ completion(' hello').line.should == 'hello'
245
+ end
246
+
247
+ it 'last whitespaces are preserved' do
248
+ completion('hello ').line.should == 'hello '
249
+ end
250
+
251
+ end
252
+
253
+ describe '#task' do
254
+
255
+ it 'is an empty string when not ending with a whitespace' do
256
+ completion('bundle install').task.should == ''
257
+ end
258
+
259
+ it 'is task given by second argument if ending with a whitespace' do
260
+ completion('bundle install ').task.should == 'install'
261
+ completion('bundle foo ').task.should == 'foo'
262
+ completion('bundle help install ').task.should == 'help'
263
+ end
264
+
265
+ end
266
+
267
+ describe '#task_options' do
268
+
269
+ it 'is correct' do
270
+ completion('bundle install --path').task_options.should == []
271
+ completion('bundle install ').task_options.should == []
272
+ completion('bundle install --path fo').task_options.should == ['--path']
273
+ completion('bundle install --path fo ').task_options.should == ['--path', 'fo']
274
+ end
275
+
276
+ end
277
+
278
+ end
@@ -0,0 +1,6 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require File.dirname(__FILE__) + '/../lib/bundler_bash_completion'
4
+
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler_bash_completion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexis Toulotte
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70259655050140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70259655050140
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70259655049560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.9.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70259655049560
36
+ description: Provides bash completion for bundle command
37
+ email: al@alweb.org
38
+ executables:
39
+ - bundler_bash_completion
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rspec
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - MIT-LICENSE
48
+ - README.mdown
49
+ - Rakefile
50
+ - VERSION
51
+ - bin/bundler_bash_completion
52
+ - bundler_bash_completion.gemspec
53
+ - lib/bundler_bash_completion.rb
54
+ - spec/bundler_bash_completion_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: https://github.com/alexistoulotte/bundler_bash_completion
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ segments:
69
+ - 0
70
+ hash: -1437438930328702423
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: -1437438930328702423
80
+ requirements: []
81
+ rubyforge_project: bundler_bash_completion
82
+ rubygems_version: 1.8.17
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Bundler bash completion
86
+ test_files:
87
+ - spec/bundler_bash_completion_spec.rb
88
+ - spec/spec_helper.rb