Skip to content

Instantly share code, notes, and snippets.

@unders
Created January 31, 2009 22:28
Show Gist options
  • Save unders/55683 to your computer and use it in GitHub Desktop.
Save unders/55683 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'thor'
require 'fileutils'
require 'yaml'
# module: tm
$SILENT = true
module Textmate
def themes
@@themes
end
def repositories
@@repositories
end
@@themes = {
:Railscasts => 'http://github.com/ryanb/textmate-themes/tree/master%2Frailscasts.tmTheme?raw=true',
:RyanLight => 'http://github.com/ryanb/textmate-themes/tree/master%2Fryan-light.tmTheme?raw=true',
:Merbivore => 'http://github.com/mig/tm_themes/tree/master%2FMerbivore.tmTheme?raw=true',
:VibrantInk => 'http://github.com/mig/tm_themes/tree/master%2FVibrant%20Ink.tmTheme?raw=true',
:GitHub => 'http://github.com/sbecker/github_textmate_theme/tree/master%2FGitHub.tmTheme?raw=true',
:idleFingers => 'http://github.com/idlefingers/idlefingers_textmate_theme/tree/master%2FidleFingers.tmTheme?raw=true'
}
@@repositories = {
'Ruby.tmbundle' => 'git://github.com/drnic/ruby-tmbundle.git',
'RSpec.tmbundle' => 'git://github.com/dchelimsky/rspec-tmbundle.git',
'Rails.tmbundle' => 'git://github.com/drnic/ruby-on-rails-tmbundle.git',
'Merb.tmbundle' => 'git://github.com/drnic/merb-tmbundle.git',
'DataMapper.tmbundle' => 'git://github.com/drnic/datamapper-tmbundle.git',
'Html.tmbundle' => 'git://github.com/drnic/html-tmbundle.git',
'Merb.tmbundle' => 'git://github.com/drnic/merb-tmbundle.git',
'JQuery.tmbundle' => 'git://github.com/drnic/javascript-jquery-tmbundle.git',
'HTML.tmbundle' => 'git://github.com/drnic/html-tmbundle.git',
'Prototype.tmbundle' => 'git://github.com/kangax/prototype-tmbundle.git',
'Git.tmbundle' => 'git://github.com/timcharper/git-tmbundle.git',
'Ruby Haml.tmbundle' => 'git://github.com/douglasjarquin/ruby-haml-tmbundle.git',
'GitHub.tmbundle' => 'git://github.com/drnic/github-tmbundle.git',
'Capistrano.tmbundle' => 'git://github.com/vigetlabs/capistrano-tmbundle.git',
'D.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/D.tmbundle',
'JavaScript Prototype & Script_aculo_us.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/JavaScript Prototype & Script_aculo_us.tmbundle',
'Latex.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/Latex.tmbundle',
'Maven.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/Maven.tmbundle',
'TextMate.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/TextMate.tmbundle',
'Subversion.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/Subversion.tmbundle',
'FileMerge.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/FileMerge.tmbundle',
'CSS.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/CSS.tmbundle',
'MacPorts.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/MacPorts.tmbundle',
'TODO.tmbundle' => 'http://macromates.com/svn/Bundles/trunk/Bundles/TODO.tmbundle'
}
#'Javascript.tmbundle' => 'git://github.com/subtleGradient/javascript.tmbundle.git',
#'JQuery.tmbundle' => 'git://github.com/kswedberg/jquery-tmbundle.git'
end
module ColorfulMessages
# red
def error(*messages)
puts messages.map { |msg| "\033[1;31m#{msg}\033[0m" }
end
# yellow
def warning(*messages)
puts messages.map { |msg| "\033[1;33m#{msg}\033[0m" }
end
# green
def success(*messages)
puts messages.map { |msg| "\033[1;32m#{msg}\033[0m" }
end
alias_method :message, :success
# magenta
def note(*messages)
puts messages.map { |msg| "\033[1;35m#{msg}\033[0m" }
end
# blue
def info(*messages)
puts messages.map { |msg| "\033[1;34m#{msg}\033[0m" }
end
end
class Tm < Thor
include Textmate
include ColorfulMessages
include FileUtils
desc 'install_theme NAME', 'Install TextMate Themes: Railscasts, RyanLight, Merbivore, VibrantInk, GitHub, idleFingers'
def install_theme(name)
if themes.include?(name.to_sym)
path = File.expand_path('~/Library/Application Support/TextMate/Themes/')
FileUtils.mkdir_p(path)
FileUtils.cd(path)
success "++ Fetching theme #{name}..."
system "curl -L #{themes[name.to_sym]} > #{name}.tmTheme "
else
error "** Theme not found."
end
end
desc 'update', 'Updates the TextMate-Bundles form GitHub'
def update
path = File.expand_path('~/Library/Application Support/TextMate/Bundles/')
mkdir_p(path)
cd(path)
repositories.each do |name, repository|
if File.exists?(name)
success "++ Updating #{name}"
cd("#{name}")
#system 'git fetch'
#system 'git checkout master'
#system 'git rebase origin/master'
#system 'git pull'
repository_update(name,repository)
cd('..')
else
success "++ Cloning #{name} repository..."
repository_clone(name,repository)
#system 'git clone #{repository} #{name}'
end
puts ''
end
system "osascript -e 'tell app \"TextMate\" to reload bundles'"
end
desc 'support_update', 'Fetch the latest TextMate-Support from subversion'
def support_update
cd(File.expand_path('~/Library/Application Support/TextMate'))
if File.exists?('Support')
cd('Support')
system 'svn update'
else
system 'svn co http://macromates.com/svn/Bundles/trunk/Support'
end
end
desc 'reload', 'TextMate to reload bundles'
def reload
system "osascript -e 'tell app \"TextMate\" to reload bundles'"
end
private
def repository_update(name,repository)
case protocol?(repository)
when 'git'
system 'git pull'
when 'svn'
system "svn up"
end
end
def repository_clone(name,repository)
case protocol?(repository)
when 'git'
system "git clone #{repository} #{name}"
when 'svn'
system "svn co #{repository} #{name}"
end
end
def protocol?(repository)
if repository =~ /http/
'svn'
elsif repository =~ /git/
'git'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment