mateup script

This script is the companion code to the entry located here. Please see there for more information, examples, and updates.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ruby -w

ENV['LC_ALL']   = nil
ENV['LC_CTYPE'] = 'en_US.UTF-8'

svn_root = 'http://macromates.com/svn/Bundles/trunk/Bundles'
bundles = [
  'Apache',                                 'AppleScript',
  'Blogging',                               'C',
  'CSS',                                    'CTags',
  'Diff',                                   'Experimental HTML',
  'Experimental Wiki',                      'Experimental',
  'FileMerge',                              'HTML',
  'JavaScript Prototype & Script_aculo_us', 'JavaScript',
  'Mail',                                   'Makefile',
  'Markdown',                               'Math',
  'Navigation',                             'Objective-C',
  'Outlines',                               'PHP',
  'PHPCodeCompletion',                      'PHPDoc',
  'Perl',                                   'Postscript',
  'Property List',                          'Python',
  'Rails',                                  'RegularExpressions',
  'Ruby',                                   'S5',
  'SQL',                                    'SSH-Config',
  'SVK',                                    'ShellScript',
  'Source',                                 'Subversion',
  'TODO',                                   'Tabular',
  'Text',                                   'TextMate',
  'Textile',                                'Web Searches',
  'XML',                                    'YAML',
  'iCalendar'
]

# escape spaces and ampersands
def cleanup(str)
  return str.gsub(/([ &])/, '\\\\\1')
end

dir = "#{ENV['HOME']}/Library/Application\ Support/TextMate/Bundles"
begin
  Dir.chdir dir
rescue Errno::ENOENT
  puts "Bundles directory doesn't exist... creating it!"
  puts
  
  `mkdir -p #{dir}`
  retry
end

Dir.entries('.').each do |e|
  next if e =~ /^\./
  next unless File.directory? e
  
  bundle_name = e.gsub(/.tmbundle$/, '')

  print "* #{bundle_name}: "

  if bundles.delete bundle_name
    puts "bundle exists, updating"
    `svn up #{cleanup e}`.match(/(revision \d+)/)
    puts "  * updated to #{$1}"
  else
    print "don't know about this bundle.  Delete it? [y/N] "

    while answer = gets
      if answer =~ /^y/
        `rm -rf #{cleanup e}`
        puts "  * deleted"
        break
      elsif answer =~ /^(n|$)/
        break
      else
        print "Please enter 'y' or 'n': "
      end
    end
  end
end

bundles.each do |bundle|
  puts "* #{bundle} doesn't exist; fetching..."
  cmd = "svn co #{svn_root}/#{cleanup bundle}.tmbundle"
  `#{cmd}`.match(/(revision \d+)/)
  puts "  * checked out #{$1}"
end