Skip to content
This repository has been archived by the owner on Oct 27, 2019. It is now read-only.

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
subtleGradient committed May 15, 2008
1 parent a35a1d8 commit 4d56257
Showing 1 changed file with 84 additions and 32 deletions.
116 changes: 84 additions & 32 deletions bin/textmate
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,61 @@ class TextmateInstaller < Thor
desc "remote [SEARCH]", "Lists all the matching remote bundles"
def remote(limit = "")
limit = Regexp.new(".*#{limit}.*", "i")
puts "\nBundles\n-------\n"
results = %x[svn list #{svn_for("bundles")}]
puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n")
puts "\nReview\n------\n"
results = %x[svn list #{svn_for("review")}]
puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n")

remote_bundle_locations.each do |name,location|
puts "\n" << name.to_s << " Remote Bundles\n" << name.to_s.gsub(/./,'-') << '---------------'

results = %x[svn list #{e_sh location[:url]}] if location[:scm]==:svn
puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n") if results

puts 'git remotes not implemented yet' if location[:scm]==:git
end
end

desc "list", "lists all the bundles installed locally"
def list()
bundles_paths.each do |location,bundles_path|
puts location.to_s << " Bundles\n" << location.to_s.gsub(/./,'-') << '--------'
local_bundle_paths.each do |name,bundles_path|
puts "\n" << name.to_s << " Bundles\n" << name.to_s.gsub(/./,'-') << '--------'
puts Dir["#{e_sh bundles_path}/*.tmbundle"].map {|x| x.split("/").last.split(".").first}.join("\n")
end
end

desc "install NAME", "install a bundle"
def install(name)
# TODO: Add a DESTINATION option to decide where to install. Maybe make some sort of ~/.textmate-cli config file?
desc "install NAME [SOURCE]", "install a bundle"
def install(bundle_name, remote_bundle_location_name=nil)
# TODO: Add an option to remove all other versions of the same bundle
FileUtils.mkdir_p install_bundles_path
type = where(name)
puts "Checking out #{name}..."
res = %x[svn co #{svn_for(type)}/#{e_sh name}.tmbundle #{e_sh install_bundles_path}/#{e_sh name}.tmbundle]
puts "Checking out #{bundle_name}..."

# CHANGED: It's faster to just try and fail for each repo than to search them all first
installed=false
remote_bundle_locations.each do |remote_name,location|
next unless remote_name.to_s.downcase.include? remote_bundle_location_name.to_s.downcase if remote_bundle_location_name

cmd = 'echo "git remotes not implemented yet"' if location[:scm]==:git
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
res = %x{#{cmd}}

puts cmd, res.gsub(/^/,' ') #if verbose # TODO: Implement a verbose mode to toggle showing all the gory details

installed=true and break if res =~ /Checked out revision|Initialized empty Git repository/
end
abort 'Not Installed' unless installed # TODO: Offer suggestions for alternate bundles with similar names. Maybe let them choose

puts "Reloading Bundles..."
reload_textmate!
puts "Done."
end

desc "uninstall NAME", "uninstall a bundle"
def uninstall(name)
def uninstall(bundle_name)
puts "Removing bundle..."
# FIXME: Move deleted bundles to the trash instead of rm_rf-ing them?
# When moving to the trash, maybe move the bundle into a trash/disabled_bundles subfolder
# named as the bundles_path key. Just in case there are multiple versions of
# the same bundle in multiple bundle paths
bundles_paths.each do |location,bundles_path|
FileUtils.rm_rf("#{bundles_path}/#{name}.tmbundle")
local_bundle_paths.each do |name,bundles_path|
FileUtils.rm_rf("#{bundles_path}/#{bundle_name}.tmbundle")
end
puts "Reloading bundles..."
reload_textmate!
Expand All @@ -56,23 +75,22 @@ class TextmateInstaller < Thor
def reload_textmate!
%x[osascript -e 'tell app "TextMate" to reload bundles']
end

def where(bundle)
bundles = %x[svn list #{svn_for("bundles")}].map {|x| x.split(".")[0]}
review = %x[svn list #{svn_for("review")}].map {|x| x.split(".")[0]}
return "bundles" if bundles.include?(bundle)
return "review" if review.include?(bundle)
end

def svn_for(type)
if type =~ /bundles/i
"http://macromates.com/svn/Bundles/trunk/Bundles"
elsif type =~ /review/i
"http://macromates.com/svn/Bundles/trunk/Review/Bundles"
end

def remote_bundle_locations
{ :'Marcomates Trunk' => {:scm => :svn, :url => 'http://macromates.com/svn/Bundles/trunk/Bundles'},
:'Marcomates Review' => {:scm => :svn, :url => 'http://macromates.com/svn/Bundles/trunk/Review/Bundles'},

This comment has been minimized.

Copy link
@evocateur

evocateur May 15, 2008

maRComates?
(I would make a cheesy joke about Marco Polo, but, er…)


# TODO: Add Git support to remote_bundle_locations. Define some sort of standard way of listing git repos, checkout how rubygems does it
# :'Bunch of Git Bundles' => {:scm => :git, :url => 'git://NotImplemented'},

# TODO: Add GitHub support as a remote_bundle_location
# This will require fetching the html of the search page, scanning for urls and converting them to git urls
# :'GitHub' => {:scm => :github, :url => 'http://github.com/search?q=tmbundle'},
}
# TODO: Add some way to add more custom remotes
end

def bundles_paths
def local_bundle_paths
{ :Application => '/Applications/TextMate.app/Contents/SharedSupport/Bundles',
:User => "#{ENV["HOME"]}/Library/Application Support/TextMate/Bundles",
:System => '/Library/Application Support/TextMate/Bundles',
Expand All @@ -83,7 +101,7 @@ class TextmateInstaller < Thor

def install_bundles_path
#TODO: Add some way for the user to configure where they'd prefer to install bundles
bundles_paths[:'User Pristine']
local_bundle_paths[:'User Pristine']
end

# Copied from http://macromates.com/svn/Bundles/trunk/Support/lib/escape.rb
Expand All @@ -94,4 +112,38 @@ class TextmateInstaller < Thor

end

# TODO: create a "monument to personal cleverness" by class-izing everything?
# class TextMateBundle
# def self.find_local(bundle_name)
#
# end
#
# def self.find_remote(bundle_name)
#
# end
# attr_reader :name
# attr_reader :location
# attr_reader :scm
# def initialize(name, location, scm)
# @name = name
# @location = location
# @scm = scm
# end
#
# def install!
#
# end
#
# def uninstall!
#
# end
#
#
# def installed?
# # List all the installed versions, and where they're at
# end
#
# # TODO: dirty? method to show if there are any deltas
# end

TextmateInstaller.start

3 comments on commit 4d56257

@subtleGradient
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYPO!?! Noooooooo :’(

:P :D

@evocateur
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll have to remember that link. :D
(Oh, and yay for Safari’s “Go To Address in New Tab” text-selection context-menu)

@subtleGradient
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. too many “!” and textile thinks anything is an image :’(

Please sign in to comment.