public
Fork of wycats/textmate
Description: Command-line package manager for textmate. Like rubygems for TextMate Bundles
Homepage: http://www.yehudakatz.com
Clone URL: git://github.com/subtleGradient/textmate.git
Refactored
[NEW] remote_bundle_locations hash of available remote bundle locations
Added a slew of todos and such
[CHANGED] Instead of looking at each repo to see shich one has the bundle 
you're looking for, just blindly try to install it from everywhere until 
it works.
  This works out to be faster than doing both since you can do it all in 
  that first connection and you're throwing around less data and stuff.
Wed May 14 23:07:38 -0700 2008
commit  4d56257e185d035e2db1d7b37b381decd22b2bf9
tree    4f3365321672cd7efe57562ff902ad7c2b1eee53
parent  a35a1d875817e9f9220f3408b0ad4297adb23fcd
...
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
...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 
 
 
 
 
 
 
 
 
 
 
 
 
73
74
75
 
76
77
78
...
83
84
85
86
 
87
88
89
...
94
95
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
...
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
...
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
93
94
95
96
...
101
102
103
 
104
105
106
107
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
0
@@ -10,42 +10,61 @@ class TextmateInstaller < Thor
0
   desc "remote [SEARCH]", "Lists all the matching remote bundles"
0
   def remote(limit = "")
0
     limit = Regexp.new(".*#{limit}.*", "i")
0
- puts "\nBundles\n-------\n"
0
- results = %x[svn list #{svn_for("bundles")}]
0
- puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n")
0
- puts "\nReview\n------\n"
0
- results = %x[svn list #{svn_for("review")}]
0
- puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n")
0
+
0
+ remote_bundle_locations.each do |name,location|
0
+ puts "\n" << name.to_s << " Remote Bundles\n" << name.to_s.gsub(/./,'-') << '---------------'
0
+
0
+ results = %x[svn list #{e_sh location[:url]}] if location[:scm]==:svn
0
+ puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n") if results
0
+
0
+ puts 'git remotes not implemented yet' if location[:scm]==:git
0
+ end
0
   end
0
   
0
   desc "list", "lists all the bundles installed locally"
0
   def list()
0
- bundles_paths.each do |location,bundles_path|
0
- puts location.to_s << " Bundles\n" << location.to_s.gsub(/./,'-') << '--------'
0
+ local_bundle_paths.each do |name,bundles_path|
0
+ puts "\n" << name.to_s << " Bundles\n" << name.to_s.gsub(/./,'-') << '--------'
0
       puts Dir["#{e_sh bundles_path}/*.tmbundle"].map {|x| x.split("/").last.split(".").first}.join("\n")
0
     end
0
   end
0
   
0
- desc "install NAME", "install a bundle"
0
- def install(name)
0
+ # TODO: Add a DESTINATION option to decide where to install. Maybe make some sort of ~/.textmate-cli config file?
0
+ desc "install NAME [SOURCE]", "install a bundle"
0
+ def install(bundle_name, remote_bundle_location_name=nil)
0
+ # TODO: Add an option to remove all other versions of the same bundle
0
     FileUtils.mkdir_p install_bundles_path
0
- type = where(name)
0
- puts "Checking out #{name}..."
0
- res = %x[svn co #{svn_for(type)}/#{e_sh name}.tmbundle #{e_sh install_bundles_path}/#{e_sh name}.tmbundle]
0
+ puts "Checking out #{bundle_name}..."
0
+
0
+ # CHANGED: It's faster to just try and fail for each repo than to search them all first
0
+ installed=false
0
+ remote_bundle_locations.each do |remote_name,location|
0
+ next unless remote_name.to_s.downcase.include? remote_bundle_location_name.to_s.downcase if remote_bundle_location_name
0
+
0
+ cmd = 'echo "git remotes not implemented yet"' if location[:scm]==:git
0
+ cmd = %[svn co #{e_sh location[:url]}/#{e_sh bundle_name}.tmbundle #{e_sh install_bundles_path}/#{e_sh bundle_name}.tmbundle 2>&1] if location[:scm]==:svn
0
+ res = %x{#{cmd}}
0
+
0
+ puts cmd, res.gsub(/^/,' ') #if verbose # TODO: Implement a verbose mode to toggle showing all the gory details
0
+
0
+ installed=true and break if res =~ /Checked out revision|Initialized empty Git repository/
0
+ end
0
+ abort 'Not Installed' unless installed # TODO: Offer suggestions for alternate bundles with similar names. Maybe let them choose
0
+
0
     puts "Reloading Bundles..."
0
     reload_textmate!
0
     puts "Done."
0
   end
0
 
0
   desc "uninstall NAME", "uninstall a bundle"
0
- def uninstall(name)
0
+ def uninstall(bundle_name)
0
     puts "Removing bundle..."
0
     # FIXME: Move deleted bundles to the trash instead of rm_rf-ing them?
0
     # When moving to the trash, maybe move the bundle into a trash/disabled_bundles subfolder
0
     # named as the bundles_path key. Just in case there are multiple versions of
0
     # the same bundle in multiple bundle paths
0
- bundles_paths.each do |location,bundles_path|
0
- FileUtils.rm_rf("#{bundles_path}/#{name}.tmbundle")
0
+ local_bundle_paths.each do |name,bundles_path|
0
+ FileUtils.rm_rf("#{bundles_path}/#{bundle_name}.tmbundle")
0
     end
0
     puts "Reloading bundles..."
0
     reload_textmate!
0
@@ -56,23 +75,22 @@ class TextmateInstaller < Thor
0
   def reload_textmate!
0
     %x[osascript -e 'tell app "TextMate" to reload bundles']
0
   end
0
-
0
- def where(bundle)
0
- bundles = %x[svn list #{svn_for("bundles")}].map {|x| x.split(".")[0]}
0
- review = %x[svn list #{svn_for("review")}].map {|x| x.split(".")[0]}
0
- return "bundles" if bundles.include?(bundle)
0
- return "review" if review.include?(bundle)
0
- end
0
-
0
- def svn_for(type)
0
- if type =~ /bundles/i
0
- "http://macromates.com/svn/Bundles/trunk/Bundles"
0
- elsif type =~ /review/i
0
- "http://macromates.com/svn/Bundles/trunk/Review/Bundles"
0
- end
0
+
0
+ def remote_bundle_locations
0
+ { :'Marcomates Trunk' => {:scm => :svn, :url => 'http://macromates.com/svn/Bundles/trunk/Bundles'},
1
+ :'Marcomates Review' => {:scm => :svn, :url => 'http://macromates.com/svn/Bundles/trunk/Review/Bundles'},
0
+
0
+ # TODO: Add Git support to remote_bundle_locations. Define some sort of standard way of listing git repos, checkout how rubygems does it
0
+ # :'Bunch of Git Bundles' => {:scm => :git, :url => 'git://NotImplemented'},
0
+
0
+ # TODO: Add GitHub support as a remote_bundle_location
0
+ # This will require fetching the html of the search page, scanning for urls and converting them to git urls
0
+ # :'GitHub' => {:scm => :github, :url => 'http://github.com/search?q=tmbundle'},
0
+ }
0
+ # TODO: Add some way to add more custom remotes
0
   end
0
   
0
- def bundles_paths
0
+ def local_bundle_paths
0
     { :Application => '/Applications/TextMate.app/Contents/SharedSupport/Bundles',
0
       :User => "#{ENV["HOME"]}/Library/Application Support/TextMate/Bundles",
0
       :System => '/Library/Application Support/TextMate/Bundles',
0
@@ -83,7 +101,7 @@ class TextmateInstaller < Thor
0
   
0
   def install_bundles_path
0
     #TODO: Add some way for the user to configure where they'd prefer to install bundles
0
- bundles_paths[:'User Pristine']
0
+ local_bundle_paths[:'User Pristine']
0
   end
0
   
0
   # Copied from http://macromates.com/svn/Bundles/trunk/Support/lib/escape.rb
0
@@ -94,4 +112,38 @@ class TextmateInstaller < Thor
0
   
0
 end
0
 
0
+# TODO: create a "monument to personal cleverness" by class-izing everything?
0
+# class TextMateBundle
0
+# def self.find_local(bundle_name)
0
+#
0
+# end
0
+#
0
+# def self.find_remote(bundle_name)
0
+#
0
+# end
0
+# attr_reader :name
0
+# attr_reader :location
0
+# attr_reader :scm
0
+# def initialize(name, location, scm)
0
+# @name = name
0
+# @location = location
0
+# @scm = scm
0
+# end
0
+#
0
+# def install!
0
+#
0
+# end
0
+#
0
+# def uninstall!
0
+#
0
+# end
0
+#
0
+#
0
+# def installed?
0
+# # List all the installed versions, and where they're at
0
+# end
0
+#
0
+# # TODO: dirty? method to show if there are any deltas
0
+# end
0
+
0
 TextmateInstaller.start

Comments