vim-update-bundles 0.6 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGES +10 -0
  2. data/README.md +52 -41
  3. data/Rakefile +23 -0
  4. data/test.rb +394 -157
  5. data/vim-update-bundles +192 -127
  6. metadata +6 -6
@@ -3,27 +3,12 @@
3
3
  # Reads bundles to be installed from the .vimrc file then synchronizes
4
4
  # .vim/bundles by downloading new repositories as needed. It also removes
5
5
  # bundles that are no longer used.
6
- #
7
- # Specify a bundle in the .vimrc:
8
- # " Bundle: https://git.wincent.com/command-t.git
9
- # Specify a refspec (branch, tag, hash) at the end:
10
- # " Bundle: https://github.com/vim-ruby/vim-ruby.git noisy
11
- # " Bundle: https://github.com/bronson/vim-closebuffer.git 0.2
12
- # " Bundle: https://github.com/tpope/vim-rails.git 42bb0699
13
- #
14
- # If the .vim folder is stored in a Git repository, add bundles as submodules
15
- # by putting "submodule=true" in ~/.vim-update-bundles.conf.
6
+ # This software is covered by the MIT License.
16
7
 
17
8
  require 'fileutils'
18
9
  require 'open-uri'
19
10
 
20
- Version = '0.6'
21
-
22
-
23
- def dotvim config, *path
24
- # Path to files inside the .vim directory, e.g., dotvim/autoload.
25
- File.join config[:vimdir_path], *path
26
- end
11
+ Version = '0.8'
27
12
 
28
13
 
29
14
  def ensure_dir dir
@@ -43,21 +28,24 @@ end
43
28
  def run *cmd
44
29
  # Runs cmd, returns its stdout, and bails on error.
45
30
  # Mostly a backport of Ruby 1.9's IO.popen for 1.8.
46
- options = { :acceptable_exit_codes => [0] }
31
+ options = { :acceptable_exit_codes => [0], :stderr => nil }
47
32
  options.merge!(cmd.pop) if cmd.last.kind_of?(Hash)
48
33
  puts "-> #{[cmd].join(" ")}" if $verbose
49
34
  outr, outw = IO::pipe
50
35
  pid = fork {
51
36
  outr.close; STDOUT.reopen outw; outw.close
37
+ STDERR.reopen '/dev/null', 'w' if options[:stderr] == :suppress
38
+ STDERR.reopen STDOUT if options[:stderr] == :merge
52
39
  exec *cmd.flatten.map { |c| c.to_s }
53
40
  }
54
41
  outw.close
55
42
  result = outr.read
56
43
  outr.close
57
44
  Process.waitpid pid
58
- unless options[:acceptable_exit_codes].include?($?.exitstatus)
45
+ if options[:acceptable_exit_codes] != :any && !options[:acceptable_exit_codes].include?($?.exitstatus)
59
46
  raise "'#{[cmd].join(" ")}' in #{Dir.pwd} exited with code #{$?.exitstatus}"
60
47
  end
48
+ puts "RESULT #{$?.exitstatus}: <<#{result}>>" if $verbose && $verbose.to_i >= 2
61
49
  result
62
50
  end
63
51
 
@@ -70,15 +58,12 @@ def git *cmd
70
58
  end
71
59
 
72
60
 
73
- def describe_head dir
74
- Dir.chdir(dir) do
75
- # Don't want to use 'git describe --all' because branch names change too often.
76
- # Use `` instead of git() so we don't error out if the git call fails.
77
- # (might happen if there's a directory in .vim/bundle that isn't git-revisioned).
78
- version = `git describe --tags 2>/dev/null`.chomp
79
- version = `git rev-parse HEAD 2>/dev/null`[0..12] unless version =~ /\S/
80
- version
81
- end
61
+ def describe_head
62
+ # Don't want to use 'git describe --all' because branch names change too often.
63
+ # This will fail if there's a directory in .vim/bundle that isn't git-revisioned.
64
+ version = git(:describe, '--tags', :acceptable_exit_codes => :any, :stderr => :suppress).chomp
65
+ version = git('rev-parse', 'HEAD', :acceptable_exit_codes => :any, :stderr => :suppress)[0..12] unless version =~ /\S/
66
+ version
82
67
  end
83
68
 
84
69
 
@@ -98,8 +83,8 @@ end
98
83
 
99
84
 
100
85
  def print_doc_entry dir, doc
101
- version = describe_head dir
102
- date = Dir.chdir(dir) { git(:log, '-1', '--pretty=format:%ai').chomp }
86
+ version = describe_head
87
+ date = git(:log, '-1', '--pretty=format:%ai').chomp
103
88
  doc.printf " %-32s %-22s %s\n", "|#{dir}|", version, date.split(' ').first
104
89
  end
105
90
 
@@ -111,7 +96,14 @@ end
111
96
 
112
97
 
113
98
  def print_log_entry log, action, dir, rev, notes=""
114
- log.printf " %-3s %-26s %-18s %s\n", action, "|#{dir}|", rev, notes
99
+ message = " %-3s %-26s %-18s %s" % [action, "|#{dir}|", rev, notes]
100
+ log.puts message.sub /\s+$/, ''
101
+ end
102
+
103
+
104
+ def log_error log, message
105
+ log.print " #{message}\n\n" # puts suppresses trailing newline
106
+ STDERR.puts message
115
107
  end
116
108
 
117
109
 
@@ -125,14 +117,30 @@ def ignore_doc_tags
125
117
  end
126
118
 
127
119
 
128
- def in_git_root inpath=nil
120
+ # Work around Ruby's useless "conflicting chdir during another chdir block" warning
121
+ # A better_chdir block can contain a Dir.chdir block,
122
+ # but a Dir.chdir block can't contain better_chdir.
123
+ def better_chdir dir
124
+ orig = Dir.pwd
125
+ begin
126
+ Dir.chdir dir
127
+ yield
128
+ ensure
129
+ # If the last bundle is removed, git will remove ~/.vim/bundle too.
130
+ ensure_dir orig
131
+ Dir.chdir orig
132
+ end
133
+ end
134
+
135
+
136
+ def in_submodule_root config, inpath=nil
129
137
  # Submodules often require the CWD to be the Git root. If a path relative to
130
138
  # the CWD is passed, the block receives it relative to the root.
131
139
  path = File.join Dir.pwd, inpath if inpath
132
- Dir.chdir("./" + git('rev-parse', '--show-cdup').chomp) do
140
+ better_chdir("./" + git('rev-parse', '--show-cdup').chomp) do
133
141
  path.sub! /^#{Dir.pwd}\/?/, '' if path
134
142
  yield path
135
- end rescue nil # Git deletes the bundle dir if it's empty.
143
+ end
136
144
  end
137
145
 
138
146
 
@@ -142,26 +150,29 @@ def clone_bundle config, dir, url, tagstr, log
142
150
  git :clone, url, dir
143
151
  else
144
152
  puts "adding submodule #{dir} from #{url}#{tagstr}"
145
- in_git_root(dir) { |mod| git :submodule, :add, url, mod }
153
+ in_submodule_root(config, dir) { |mod| git :submodule, :add, url, mod }
146
154
  end
147
- print_log_entry log, 'Add', dir, describe_head(dir), "#{url}#{tagstr}"
155
+ Dir.chdir(dir) { print_log_entry log, 'Add', dir, describe_head, "#{url}#{tagstr}" }
156
+ $bundles_added += 1
148
157
  end
149
158
 
150
159
 
151
160
  def remove_bundle_to config, dir, destination
152
- puts "Erasing #{dir}, find it in #{destination}"
161
+ puts "Removing #{dir}, find it in #{destination}"
153
162
  FileUtils.mv dir, destination
154
163
  if config[:submodule]
155
- in_git_root(dir) do |mod|
164
+ in_submodule_root(config, dir) do |mod|
156
165
  git :rm, mod
166
+ fn = nil
157
167
  ['.gitmodules', '.git/config'].each do |filename|
158
168
  begin
169
+ fn = filename
159
170
  text = File.read filename
160
171
  File.open(filename, 'w+') do |file|
161
172
  file.puts text.gsub(/\[submodule "#{mod}"\][^\[]+/m,'')
162
173
  end
163
- rescue
164
- puts " Could not delete submodule entries from .gitmodules and .git/config"
174
+ rescue Exception => e
175
+ raise "could not delete #{dir} from #{fn}: #{e}"
165
176
  end
166
177
  end
167
178
  end
@@ -170,13 +181,15 @@ end
170
181
 
171
182
 
172
183
  def remove_bundle config, dir, log
173
- print_log_entry log, 'Del', dir, describe_head(dir)
174
- trash_dir = dotvim(config, "Trashed-Bundles")
184
+ Dir.chdir(dir) { print_log_entry log, 'Del', dir, describe_head }
185
+ trash_dir = "#{config[:vimdir_path]}/Trashed-Bundles"
175
186
  ensure_dir trash_dir
176
- 1.upto(100) do |i|
177
- destination = "#{trash_dir}/#{dir}-#{'%02d' % i}"
187
+ suffixes = [''] + (1..99).map { |i| "-#{"%02d" % i}" }
188
+ suffixes.each do |suffix|
189
+ destination = "#{trash_dir}/#{dir}#{suffix}"
178
190
  unless test ?d, destination
179
191
  remove_bundle_to config, dir, destination
192
+ $bundles_removed += 1
180
193
  return
181
194
  end
182
195
  end
@@ -184,47 +197,54 @@ def remove_bundle config, dir, log
184
197
  end
185
198
 
186
199
 
187
- def update_bundle config, dir, tag, tagstr, previous_version, log
188
- Dir.chdir(dir) do
189
- git :checkout, tag || :master
190
- if system 'git symbolic-ref HEAD -q >/dev/null'
191
- # only pull if symbolic-ref is true, otherwise it's detached head
192
- git :pull, '--ff-only', :origin, tag || :master
193
- end
194
- ignore_doc_tags
195
- end
200
+ def reset_bundle config, dir, url, tagstr, log
201
+ remove_bundle config, dir, log
202
+ ensure_dir "#{config[:vimdir_path]}/bundle"
203
+ clone_bundle config, dir, url, tagstr, log
204
+ end
205
+
196
206
 
197
- if previous_version
198
- new_version = describe_head dir
199
- if new_version != previous_version
200
- print_log_entry log, 'up', dir, previous_version, "-> #{new_version}#{tagstr}"
207
+ def pull_bundle dir, tag, log
208
+ git :fetch, :origin, :stderr => :suppress # git prints some needless warnings during fetch
209
+ git :checkout, tag || :master
210
+
211
+ # if it's a branch, we need to merge in upstream changes
212
+ if system 'git symbolic-ref HEAD -q >/dev/null'
213
+ output = git(:merge, '--ff-only', "origin/#{tag || :master}", :acceptable_exit_codes => :any, :stderr => :merge)
214
+ unless $?.success?
215
+ log_error log, output.gsub(/\s+/, ' ')
216
+ return false # bundle is not OK and needs to be reset
201
217
  end
202
218
  end
203
219
 
204
- in_git_root(dir) { |mod| git :add, mod } if config[:submodule]
220
+ return true # bundle is good, let's continue
205
221
  end
206
222
 
207
223
 
208
- def download_bundle config, dir, url, tag, doc, log
224
+ def install_bundle config, dir, url, tag, doc, log
209
225
  tagstr = " at #{tag}" if tag
210
226
  previous_version = nil
211
227
  only_updating = false
212
228
 
229
+ if url.match /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/ # User/repository.
230
+ url = "https://github.com/#{url}.git"
231
+ end
232
+ if url.match /^[A-Za-z0-9._-]+$/ # Plain repository.
233
+ url = "https://github.com/vim-scripts/#{url}.git"
234
+ end
235
+
213
236
  # fetch bundle
214
237
  if test ?d, dir
215
238
  remote = Dir.chdir(dir) { git(:config, '--get', 'remote.origin.url').chomp }
216
239
  if remote == url
217
240
  only_updating = true
218
241
  unless config[:no_updates]
219
- previous_version = describe_head dir
242
+ Dir.chdir(dir) { previous_version = describe_head }
220
243
  puts "updating #{dir} from #{url}#{tagstr}"
221
- Dir.chdir(dir) { git :fetch }
222
244
  end
223
245
  else
224
- puts "repo has changed from #{remote} to #{url}"
225
- remove_bundle config, dir, log
226
- ensure_dir dotvim(config, 'bundle')
227
- clone_bundle config, dir, url, tagstr, log
246
+ log_error log, "bundle for #{dir} changed from #{remote} to #{url}"
247
+ reset_bundle config, dir, url, tagstr, log
228
248
  end
229
249
  else
230
250
  clone_bundle config, dir, url, tagstr, log
@@ -232,10 +252,24 @@ def download_bundle config, dir, url, tag, doc, log
232
252
 
233
253
  # pull bundle
234
254
  unless only_updating && config[:no_updates]
235
- update_bundle config, dir, tag, tagstr, previous_version, log
255
+ unless Dir.chdir(dir) { pull_bundle dir, tag, log }
256
+ reset_bundle config, dir, url, tagstr, log
257
+ end
258
+ Dir.chdir(dir) do
259
+ ignore_doc_tags
260
+ if previous_version
261
+ new_version = describe_head
262
+ if new_version != previous_version
263
+ print_log_entry log, 'up', dir, "#{new_version}#{tagstr}", "<- #{previous_version}"
264
+ $bundles_updated += 1 if only_updating
265
+ end
266
+ end
267
+ end
236
268
  end
237
269
 
238
- print_doc_entry dir, doc
270
+ Dir.chdir(dir) { print_doc_entry dir, doc }
271
+ in_submodule_root(config, dir) { |mod| git :add, mod } if config[:submodule]
272
+
239
273
  only_updating
240
274
  end
241
275
 
@@ -260,33 +294,51 @@ def run_bundle_command dir, cmd
260
294
  end
261
295
 
262
296
 
297
+ def vim_string str
298
+ if str.slice(0,1) == "'"
299
+ str =~ /^\s*'(.*)'\s*$/
300
+ return $1.gsub "''", "'"
301
+ elsif str.slice(0,1) == '"'
302
+ str =~ /^\s*"(.*)"\s*$/
303
+ return $1 # could do escape substitution here
304
+ else
305
+ return str
306
+ end
307
+ end
308
+
309
+
263
310
  def update_bundles config, doc, log
264
311
  existing_bundles = Dir['*']
312
+ updated_bundles = {}
265
313
 
266
314
  # Ignore files in the bundle directory, e.g., READMEs.
267
315
  existing_bundles.reject! { |path| FileTest.file? path }
268
316
 
269
317
  dir = only_updating = nil
270
318
  puts "# reading vimrc" if config[:verbose]
319
+ string_re = %q{'([^']+|'')*'|"[^"]*"} # captures single and double quoted Vim strings
271
320
  read_vimrc(config) do |line|
272
- if line =~ /^\s*"\s*bundle:\s*(.*)$/i
273
- url, tag = $1.split
321
+ if line =~ /^\s*"\s*bundle:\s*(.*)$/i ||
322
+ line =~ /^\s*Bundle\s*(#{string_re})/
323
+ url, tag = vim_string($1).split
274
324
  puts "# processing '#{url}' at '#{tag}'" if config[:verbose]
275
- dir = url.split('/').last.gsub(/^vim-|\.git$/, '')
276
- if url.match /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/ # User/repository.
277
- url = "https://github.com/#{url}.git"
278
- end
279
- if url.match /^[A-Za-z0-9._-]+$/ # Plain repository.
280
- url = "https://github.com/vim-scripts/#{url}.git"
281
- end
282
- only_updating = download_bundle config, dir, url, tag, doc, log
325
+ dir = url.split('/').last.sub(/\.git$/, '')
326
+
327
+ # quick sanity check
328
+ raise "duplicate entry for #{url}" if updated_bundles[dir] == url
329
+ raise "urls map to the same bundle: #{updated_bundles[dir]} and #{url}" if updated_bundles[dir]
330
+
331
+ only_updating = install_bundle config, dir, url, tag, doc, log
332
+ updated_bundles[dir] = url
283
333
  existing_bundles.delete dir
284
- elsif line =~ /^\s*"\s*bundle[ -]?command:\s*(.*)$/i
334
+ elsif line =~ /^\s*"\s*bundle[ -]?command:\s*(.*)$/i ||
335
+ line =~ /^\s*BundleCommand\s*(#{string_re})$/
285
336
  # Want BundleCommand but BUNDLE COMMAND and Bundle-Command used to be legal too
286
337
  raise "BundleCommand must come after Bundle" if dir.nil?
287
- run_bundle_command dir, $1 unless only_updating && config[:no_updates]
288
- elsif line =~ /^\s*"\s*static:\s*(.*)$/i
289
- dir = $1
338
+ run_bundle_command dir, vim_string($1) unless only_updating && config[:no_updates]
339
+ elsif line =~ /^\s*"\s*static:\s*(.*)$/i ||
340
+ line =~ /^\s*Bundle!\s*(#{string_re})$/i
341
+ dir = vim_string $1
290
342
  puts " leaving #{dir} alone"
291
343
  existing_bundles.delete dir
292
344
  end
@@ -294,7 +346,7 @@ def update_bundles config, doc, log
294
346
  existing_bundles.each { |dir| remove_bundle config, dir, log }
295
347
 
296
348
  if config[:submodule]
297
- in_git_root do
349
+ in_submodule_root(config) do
298
350
  puts " updating submodules"
299
351
  git :submodule, :init
300
352
  git :submodule, :update
@@ -303,27 +355,45 @@ def update_bundles config, doc, log
303
355
  end
304
356
 
305
357
 
358
+ def bundleize count
359
+ "#{count} bundle#{count != 1 ? 's' : ''}"
360
+ end
361
+
362
+ def bundle_count_string
363
+ str = []
364
+ str << "#{bundleize $bundles_added} added" if $bundles_added > 0
365
+ str << "#{bundleize $bundles_removed} removed" if $bundles_removed > 0
366
+ str << "#{bundleize $bundles_updated} updated" if $bundles_updated > 0
367
+ return "no updates" if str.empty?
368
+
369
+ str[-1] = "and #{str[-1]}" if str.size > 2
370
+ str.join(", ")
371
+ end
372
+
373
+
306
374
  def update_bundles_and_docs config
307
- ensure_dir dotvim(config, 'doc')
308
- bundle_dir = dotvim(config, 'bundle')
375
+ ensure_dir "#{config[:vimdir_path]}/doc"
376
+ bundle_dir = "#{config[:vimdir_path]}/bundle"
309
377
  ensure_dir bundle_dir
378
+ $bundles_added = $bundles_removed = $bundles_updated = 0
310
379
 
311
- File.open(dotvim(config, 'doc', 'bundles.txt'), "w") do |doc|
380
+ File.open("#{config[:vimdir_path]}/doc/bundles.txt", "w") do |doc|
312
381
  print_doc_header doc
313
- logfile = dotvim(config, 'doc', 'bundle-log.txt')
382
+ logfile = "#{config[:vimdir_path]}/doc/bundle-log.txt"
314
383
  log_already_exists = test ?f, logfile
315
384
  File.open(logfile, 'a') do |log|
316
385
  print_log_header log unless log_already_exists
317
- log.puts "Updating on #{current_date}"
386
+ log.puts "#{current_date} by vim-update-bundles #{Version}"
318
387
  begin
319
- Dir.chdir(bundle_dir) { update_bundles config, doc, log }
388
+ better_chdir(bundle_dir) { update_bundles config, doc, log }
320
389
  rescue Exception => e
321
390
  message = e.is_a?(Interrupt) ? "Interrupted" : "Aborted: #{e.message}"
322
- log.print " #{message}\n\n" # puts suppresses trailing newline
391
+ log_error log, message
323
392
  doc.puts message
324
- STDERR.puts message
393
+ STDERR.puts e.backtrace if ENV['TRACE']
325
394
  exit e.respond_to?(:exit_code) ? e.exit_code : 1
326
395
  end
396
+ log.puts " " + bundle_count_string
327
397
  log.puts
328
398
  end
329
399
  doc.puts
@@ -333,7 +403,7 @@ end
333
403
 
334
404
  def interpolate options, val, message, i
335
405
  raise "Interpolation is now $#{$1} instead of ENV[#{$1}] #{message} #{i}" if val =~ /ENV\[['"]?([^\]]*)['"]?\]/
336
- STDERR.puts "WARNING: quotes in a config item are probably a mistake #{message} #{i}" if val =~ /["']/
406
+ STDERR.puts "WARNING: putting quotes in a config item is probably a mistake #{message} #{i}" if val =~ /["']/
337
407
 
338
408
  val.gsub(/\$([A-Za-z0-9_]+)/) { options[$1.to_sym] || ENV[$1] || raise("$#{$1} is not defined #{message} #{i}") }
339
409
  end
@@ -349,56 +419,36 @@ def process_options options, args, message
349
419
  k.gsub! '-', '_' # underscorize args, 'no-updates' -> 'no_updates'
350
420
 
351
421
  unless options.has_key? k.to_sym
352
- puts "Unknown option: #{k.inspect} #{message} #{i}"
422
+ STDERR.puts "Unknown option: #{k.inspect} #{message} #{i}"
353
423
  puts "Usage: #{help}" if args.equal? ARGV
354
424
  exit 1
355
425
  end
356
426
 
357
427
  v = options[k.to_sym].call(v) if options[k.to_sym].is_a? Proc
358
- options[k.to_sym] = v ? interpolate(options,v,message,i).split("'").join("\\'") : true
428
+ options[k.to_sym] = v ? interpolate(options,v,message,i).split("'").join("\\'") : 1 + (options[k.to_sym] || 0)
359
429
  end
360
430
  end
361
431
 
362
432
 
363
433
  # Returns the first path that exists or the last one if nothing exists.
364
- def choose_file *paths
365
- paths.find { |p| test ?f, p } || paths[-1]
366
- end
367
-
368
-
369
- def set_default_options opts
370
- dotfiles = File.join(ENV['HOME'], '.dotfiles')
371
- opts[:dotfiles_path] ||= dotfiles if test(?d, dotfiles)
372
-
373
- if opts[:dotfiles_path]
374
- raise "#{opts[:dotfiles_path]} doesn't exist!" unless test(?d, opts[:dotfiles_path])
375
- opts[:vimdir_path] ||= File.join(opts[:dotfiles_path], 'vim')
376
- opts[:vimrc_path] ||= choose_file(File.join([opts[:dotfiles_path], 'vim', 'vimrc']),
377
- File.join([opts[:dotfiles_path], 'vimrc']))
378
- else
379
- opts[:vimdir_path] ||= File.join(ENV['HOME'], '.vim')
380
- opts[:vimrc_path] ||= choose_file(File.join([ENV['HOME'], '.vim', 'vimrc']),
381
- File.join([ENV['HOME'], '.vimrc']))
382
- end
434
+ def choose_path *paths
435
+ paths.find { |p| test ?e, p } || paths[-1]
383
436
  end
384
437
 
385
438
 
386
439
  def ensure_vim_environment config
387
- ensure_dir dotvim(config)
388
- ensure_dir dotvim(config, 'autoload')
440
+ ensure_dir config[:vimdir_path]
441
+ ensure_dir "#{config[:vimdir_path]}/autoload"
389
442
 
390
- unless test ?f, dotvim(config, 'autoload', 'pathogen.vim')
443
+ unless test ?f, "#{config[:vimdir_path]}/autoload/pathogen.vim"
391
444
  puts "Downloading Pathogen..."
392
- download_file config[:pathogen_url], dotvim(config, 'autoload', 'pathogen.vim')
445
+ download_file config[:pathogen_url], "#{config[:vimdir_path]}/autoload/pathogen.vim"
393
446
  end
394
447
 
395
448
  unless test(?f, config[:vimrc_path])
396
449
  puts "Downloading starter vimrc..."
397
450
  download_file config[:starter_url], config[:vimrc_path]
398
451
  end
399
-
400
- run :ln, '-s', config[:vimdir_path], "#{ENV['HOME']}/.vim" unless test ?e, "#{ENV['HOME']}/.vim"
401
- run :ln, '-s', config[:vimrc_path], "#{ENV['HOME']}/.vimrc" unless test ?e, "#{ENV['HOME']}/.vimrc"
402
452
  end
403
453
 
404
454
 
@@ -409,15 +459,32 @@ def generate_helptags
409
459
  end
410
460
 
411
461
 
462
+ def locate_vim_files config
463
+ vimdir_guess = choose_path "#{ENV['HOME']}/.dotfiles/vim", "#{ENV['HOME']}/.vim"
464
+
465
+ vimrc_guesses = []
466
+ if config[:vimdir_path]
467
+ vimrc_guesses.push "#{config[:vimdir_path]}/.vimrc", "#{config[:vimdir_path]}/vimrc"
468
+ end
469
+ vimrc_guesses.push "#{ENV['HOME']}/.dotfiles/vimrc", "#{ENV['HOME']}/.vimrc"
470
+ vimrc_guess = choose_path *vimrc_guesses
471
+
472
+ config[:vimdir_path] ||= vimdir_guess
473
+ config[:vimrc_path] ||= vimrc_guess
474
+ end
475
+
476
+
412
477
  def read_configuration config
413
478
  conf_file = File.join ENV['HOME'], '.vim-update-bundles.conf'
414
479
  process_options config, File.open(conf_file).readlines, "in #{conf_file} line" if test(?f, conf_file)
415
480
  process_options config, ARGV, "in command line argument"
416
481
 
417
- set_default_options config
482
+ locate_vim_files config
418
483
 
419
- config.keys.sort.each { |k| puts "# option #{k} = #{config[k].inspect}" } if config[:verbose]
420
- config.delete :dotfiles_path # Ensure it is not used accidentally later.
484
+ actual_keys = config.keys.reject { |k| config[k].is_a? Proc or config[k].is_a? Symbol }
485
+ actual_keys.map { |k| k.to_s }.sort.each do |k|
486
+ puts "# option #{k} = #{config[k.to_sym].inspect}"
487
+ end if config[:verbose]
421
488
  end
422
489
 
423
490
 
@@ -427,12 +494,11 @@ vim-update-bundles [options...]
427
494
  Updates the installed Vim plugins.
428
495
  -n --no-updates: don't update bundles, only add or delete (faster)
429
496
  -h -? --help: print this message
430
- -v --verbose: print exactly what's happening
497
+ -v --verbose: print what's happening (multiple -v for more verbose)
431
498
  optional configurations:
432
499
  -s --submodule: store bundles as git submodules
433
500
  --vimdir-path: path to ~/.vim directory
434
501
  --vimrc-path: path to ~/.vimrc directory
435
- --dotfiles-path: path to your dotfiles if different than $HOME.
436
502
  EOL
437
503
  end
438
504
 
@@ -449,9 +515,8 @@ config = {
449
515
  :v => :verbose, :s => :submodule, :n => :no_updates,
450
516
  :h => :help, :'?' => :help, :V => :version,
451
517
 
452
- :dotfiles_path => nil, # Full path to the dot files directory.
453
- :vimdir_path => nil, # Full path to ~/.vim (creates symlink if not in $HOME).
454
- :vimrc_path => nil, # Full path to ~/.vimrc (creates symlink if not in $HOME).
518
+ :vimdir_path => nil, # Full path to ~/.vim
519
+ :vimrc_path => nil, # Full path to ~/.vimrc
455
520
 
456
521
  # Used when spinning up a new Vim environment.
457
522
  :starter_url => "https://github.com/bronson/dotfiles/raw/master/.vimrc",