wycats-textmate 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +31 -0
  3. data/Rakefile +46 -0
  4. data/bin/textmate +149 -0
  5. data/lib/class_cli.rb +77 -0
  6. metadata +66 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yehuda Katz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ textmate
2
+ ========
3
+
4
+ A binary that provides package management for TextMate.
5
+
6
+ Usage
7
+ =====
8
+
9
+ `textmate [COMMAND] [*PARAMS]`
10
+
11
+ Textmate bundles are automatically reloaded after install or uninstall operations.
12
+
13
+ `textmate remote [SEARCH]`
14
+ ------------------------
15
+
16
+ List all of the available bundles in the remote repository that have a substring `search`. By default, list all bundles.
17
+
18
+ `textmate list`
19
+ --------------------
20
+
21
+ List all of the bundles that are installed on the local system.
22
+
23
+ `textmate install NAME [SOURCE]`
24
+ -----------------------
25
+
26
+ Installs a bundle from the remote repository. SOURCE filters known remote bundle locations.
27
+
28
+ `textmate uninstall NAME`
29
+ -------------------------
30
+
31
+ Uninstalls a bundle from the local repository.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'date'
4
+
5
+ GEM = "textmate"
6
+ GEM_VERSION = "0.9.0"
7
+ AUTHOR = "Yehuda Katz"
8
+ EMAIL = "wycats@gmail.com"
9
+ HOMEPAGE = "http://yehudakatz.com"
10
+ SUMMARY = "Command-line textmate package manager"
11
+
12
+ spec = Gem::Specification.new do |s|
13
+ s.name = GEM
14
+ s.version = GEM_VERSION
15
+ s.platform = Gem::Platform::RUBY
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ["README.markdown", "LICENSE"]
18
+ s.summary = SUMMARY
19
+ s.description = s.summary
20
+ s.author = AUTHOR
21
+ s.email = EMAIL
22
+ s.homepage = HOMEPAGE
23
+
24
+ s.add_dependency "thor", ">= 0.9.1"
25
+
26
+ s.require_path = 'lib'
27
+ s.autorequire = GEM
28
+ s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("{bin,lib,specs}/**/*")
29
+ s.bindir = "bin"
30
+ s.executables = %w( textmate )
31
+ end
32
+
33
+ Rake::GemPackageTask.new(spec) do |pkg|
34
+ pkg.gem_spec = spec
35
+ end
36
+
37
+ desc "make a gemspec file"
38
+ task :make_spec do
39
+ File.open("#{GEM}.gemspec", "w") do |file|
40
+ file.puts spec.to_ruby
41
+ end
42
+ end
43
+
44
+ task :install => [:package] do
45
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION} --no-rdoc --no-ri}
46
+ end
data/bin/textmate ADDED
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fileutils"
4
+ require "rubygems"
5
+ require "thor"
6
+
7
+ class TextmateInstaller < Thor
8
+
9
+ # CHANGED: renamed list to remote. Could there be a better name?
10
+ desc "remote [SEARCH]", "Lists all the matching remote bundles"
11
+ def remote(limit = "")
12
+ limit = Regexp.new(".*#{limit}.*", "i")
13
+
14
+ remote_bundle_locations.each do |name,location|
15
+ puts "\n" << name.to_s << " Remote Bundles\n" << name.to_s.gsub(/./,'-') << '---------------'
16
+
17
+ results = %x[svn list #{e_sh location[:url]}] if location[:scm]==:svn
18
+ puts results.map {|x| x.split(".")[0]}.select {|x| x =~ limit}.join("\n") if results
19
+
20
+ puts 'git remotes not implemented yet' if location[:scm]==:git
21
+ end
22
+ end
23
+
24
+ desc "list", "lists all the bundles installed locally"
25
+ def list()
26
+ local_bundle_paths.each do |name,bundles_path|
27
+ puts "\n" << name.to_s << " Bundles\n" << name.to_s.gsub(/./,'-') << '--------'
28
+ puts Dir["#{e_sh bundles_path}/*.tmbundle"].map {|x| x.split("/").last.split(".").first}.join("\n")
29
+ end
30
+ end
31
+
32
+ # TODO: Add a DESTINATION option to decide where to install. Maybe make some sort of ~/.textmate-cli config file?
33
+ desc "install NAME [SOURCE]", "install a bundle"
34
+ def install(bundle_name, remote_bundle_location_name=nil)
35
+ # TODO: Add an option to remove all other versions of the same bundle
36
+ FileUtils.mkdir_p install_bundles_path
37
+ puts "Checking out #{bundle_name}..."
38
+
39
+ # CHANGED: It's faster to just try and fail for each repo than to search them all first
40
+ installed=false
41
+ remote_bundle_locations.each do |remote_name,location|
42
+ next unless remote_name.to_s.downcase.include? remote_bundle_location_name.to_s.downcase if remote_bundle_location_name
43
+
44
+ cmd = 'echo "git remotes not implemented yet"' if location[:scm]==:git
45
+ 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
46
+ res = %x{#{cmd}}
47
+
48
+ puts cmd, res.gsub(/^/,' ') #if verbose # TODO: Implement a verbose mode to toggle showing all the gory details
49
+
50
+ installed=true and break if res =~ /Checked out revision|Initialized empty Git repository/
51
+ end
52
+ abort 'Not Installed' unless installed # TODO: Offer suggestions for alternate bundles with similar names. Maybe let them choose
53
+
54
+ puts "Reloading Bundles..."
55
+ reload_textmate!
56
+ puts "Done."
57
+ end
58
+
59
+ desc "uninstall NAME", "uninstall a bundle"
60
+ def uninstall(bundle_name)
61
+ puts "Removing bundle..."
62
+ # FIXME: Move deleted bundles to the trash instead of rm_rf-ing them?
63
+ # When moving to the trash, maybe move the bundle into a trash/disabled_bundles subfolder
64
+ # named as the bundles_path key. Just in case there are multiple versions of
65
+ # the same bundle in multiple bundle paths
66
+ local_bundle_paths.each do |name,bundles_path|
67
+ FileUtils.rm_rf("#{bundles_path}/#{bundle_name}.tmbundle")
68
+ end
69
+ puts "Reloading bundles..."
70
+ reload_textmate!
71
+ puts "Done."
72
+ end
73
+
74
+ private
75
+ def reload_textmate!
76
+ %x[osascript -e 'tell app "TextMate" to reload bundles']
77
+ end
78
+
79
+ def remote_bundle_locations
80
+ { :'Marcomates Trunk' => {:scm => :svn, :url => 'http://macromates.com/svn/Bundles/trunk/Bundles'},
81
+ :'Marcomates Review' => {:scm => :svn, :url => 'http://macromates.com/svn/Bundles/trunk/Review/Bundles'},
82
+
83
+ # TODO: Add Git support to remote_bundle_locations. Define some sort of standard way of listing git repos, checkout how rubygems does it
84
+ # :'Bunch of Git Bundles' => {:scm => :git, :url => 'git://NotImplemented'},
85
+
86
+ # TODO: Add GitHub support as a remote_bundle_location
87
+ # This will require fetching the html of the search page, scanning for urls and converting them to git urls
88
+ # :'GitHub' => {:scm => :github, :url => 'http://github.com/search?q=tmbundle'},
89
+ }
90
+ # TODO: Add some way to add more custom remotes
91
+ end
92
+
93
+ def local_bundle_paths
94
+ { :Application => '/Applications/TextMate.app/Contents/SharedSupport/Bundles',
95
+ :User => "#{ENV["HOME"]}/Library/Application Support/TextMate/Bundles",
96
+ :System => '/Library/Application Support/TextMate/Bundles',
97
+ :'User Pristine' => "#{ENV["HOME"]}/Library/Application Support/TextMate/Pristine Copy",
98
+ :'System Pristine' => '/Library/Application Support/TextMate/Pristine Copy',
99
+ }
100
+ end
101
+
102
+ def install_bundles_path
103
+ #TODO: Add some way for the user to configure where they'd prefer to install bundles
104
+ local_bundle_paths[:'User Pristine']
105
+ end
106
+
107
+ # Copied from http://macromates.com/svn/Bundles/trunk/Support/lib/escape.rb
108
+ # escape text to make it useable in a shell script as one “word” (string)
109
+ def e_sh(str)
110
+ str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
111
+ end
112
+
113
+ end
114
+
115
+ # TODO: create a "monument to personal cleverness" by class-izing everything?
116
+ # class TextMateBundle
117
+ # def self.find_local(bundle_name)
118
+ #
119
+ # end
120
+ #
121
+ # def self.find_remote(bundle_name)
122
+ #
123
+ # end
124
+ # attr_reader :name
125
+ # attr_reader :location
126
+ # attr_reader :scm
127
+ # def initialize(name, location, scm)
128
+ # @name = name
129
+ # @location = location
130
+ # @scm = scm
131
+ # end
132
+ #
133
+ # def install!
134
+ #
135
+ # end
136
+ #
137
+ # def uninstall!
138
+ #
139
+ # end
140
+ #
141
+ #
142
+ # def installed?
143
+ # # List all the installed versions, and where they're at
144
+ # end
145
+ #
146
+ # # TODO: dirty? method to show if there are any deltas
147
+ # end
148
+
149
+ TextmateInstaller.start
data/lib/class_cli.rb ADDED
@@ -0,0 +1,77 @@
1
+ require "getopt/long"
2
+
3
+ module Hermes
4
+ def self.extended(klass)
5
+ klass.class_eval <<-RUBY, "class_cli.rb", 6
6
+
7
+ def self.method_added(meth)
8
+ return if !public_instance_methods.include?(meth.to_s) || !@@usage
9
+ @@descriptions = defined?(@@descriptions) ? @@descriptions : []
10
+ @@usages = defined?(@@usages) ? @@usages : []
11
+ @@opts = defined?(@@opts) ? @@opts : []
12
+ @@descriptions << [meth.to_s, @@desc]
13
+ @@usages << [meth.to_s, @@usage]
14
+ if defined?(@@method_options) && @@method_options
15
+ @@opts << [meth.to_s, @@method_options]
16
+ end
17
+ @@usage, @@desc, @@method_options = nil
18
+ end
19
+
20
+ def self.desc(usage, description)
21
+ @@usage, @@desc = usage, description
22
+ end
23
+
24
+ def self.method_options(opts)
25
+ @@method_options = opts
26
+ end
27
+
28
+ def self.start
29
+ meth = ARGV.shift
30
+ params = ARGV.inject([]) do |accum, arg|
31
+ accum << ARGV.delete(arg) unless arg =~ /^\-/
32
+ accum
33
+ end
34
+ if @@opts.assoc(meth)
35
+ opts = @@opts.assoc(meth).last.map {|opt, val| [opt, val == true ? Getopt::BOOLEAN : Getopt.const_get(val)].flatten}
36
+ options = Getopt::Long.getopts(*opts)
37
+ params << options
38
+ end
39
+ new(meth, params)
40
+ end
41
+
42
+ def initialize(op, params)
43
+ send(op.to_sym, *params) if public_methods.include?(op)
44
+ end
45
+
46
+ private
47
+ def format_opts(opts)
48
+ return "" unless opts
49
+ opts.map do |opt, val|
50
+ if val == true || val == "BOOLEAN"
51
+ opt
52
+ elsif val == "REQUIRED"
53
+ opt + "=" + opt.gsub(/\-/, "").upcase
54
+ elsif val == "OPTIONAL"
55
+ "[" + opt + "=" + opt.gsub(/\-/, "").upcase + "]"
56
+ end
57
+ end.join(" ")
58
+ end
59
+
60
+ public
61
+ desc "help", "show this screen"
62
+ def help
63
+ puts "Options"
64
+ puts "-------"
65
+ max_usage = @@usages.max {|x,y| x.last.to_s.size <=> y.last.to_s.size}.last.size
66
+ max_opts = @@opts.empty? ? 0 : format_opts(@@opts.max {|x,y| x.last.to_s.size <=> y.last.to_s.size}.last).size
67
+ max_desc = @@descriptions.max {|x,y| x.last.to_s.size <=> y.last.to_s.size}.last.size
68
+ @@usages.each do |meth, usage|
69
+ format = "%-" + (max_usage + max_opts + 4).to_s + "s"
70
+ print format % (@@usages.assoc(meth)[1] + (@@opts.assoc(meth) ? " " + format_opts(@@opts.assoc(meth)[1]) : ""))
71
+ # print format % (@@usages.assoc(meth)[1] + @@opts.assoc(meth) ? format_opts(@@opts.assoc(meth)[1]) : ""))
72
+ puts @@descriptions.assoc(meth)[1]
73
+ end
74
+ end
75
+ RUBY
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wycats-textmate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Yehuda Katz
8
+ autorequire: textmate
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-19 00:00:00 -07:00
13
+ default_executable: textmate
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.1
23
+ version:
24
+ description: Command-line textmate package manager
25
+ email: wycats@gmail.com
26
+ executables:
27
+ - textmate
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.markdown
32
+ - LICENSE
33
+ files:
34
+ - LICENSE
35
+ - README.markdown
36
+ - Rakefile
37
+ - bin/textmate
38
+ - lib/class_cli.rb
39
+ has_rdoc: true
40
+ homepage: http://yehudakatz.com
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.0.1
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Command-line textmate package manager
65
+ test_files: []
66
+