Class: TextMateBundleManager
- Inherits:
-
Thor
- Object
- Thor
- TextMateBundleManager
show all
- Defined in:
- lib/textmate/bundle.rb,
lib/textmate/commands.rb,
lib/textmate/repository.rb
Overview
TODO “Move” task TODO “Copy” task? TODO “Rename” task? TODO “Shell” or “Find” task TODO “Finder” task – open relevant directory in the Finder TODO “Where” or “Which” task TODO “Push” task? TODO “Pull” task? Is this different from update? TODO “Edit” task TODO “Hide” task TODO “Show” task (i.e. reverse of Hide) TODO “Duplicates” task TODO “Find” task – e.g. find all bundles linked to svn, find all dirty, etc. (or options to list command?)
Defined Under Namespace
Classes: Bundle, RemoteRepository, Repository, SVNRepository, TextMateRepository
Constant Summary
collapse
- VALID_SCM_TYPES =
%w{git svn github}
Instance Method Summary
collapse
Instance Method Details
#get(bundle_name = nil, repo_path = nil) ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/textmate/commands.rb', line 229
def get(bundle_name=nil, repo_path=nil)
replacements = 0
if options[:exact]
bundle_name = bundle_name.to_s
bundle_name += '.tmbundle' unless bundle_name =~ /\.tmbundle$/
search_pattern =/^#{Regexp.escape(bundle_name.to_s)}$/
else
search_pattern = /#{Regexp.escape(bundle_name.to_s)}[^\/]*\.tmbundle$/i
end
fixed_source = if repo_path
{
:scm => repo_path =~ /github/ ? :github : (repo_path =~ /git/ ? :git : :svn),
:repo => repo_path,
:file => File.basename(repo_path),
:short => :manual,
:name => :'Manually Provided',
}
else
nil
end
each_local_bundle do |path|
next if !bundle_name.nil? && File.basename(path) !~ search_pattern install_bundle_name = File.basename(path)
found_bundle_name = File.basename(path, '.*')
install_location = options[:system] ? 'System' : 'User'
source = nil
[install_location.to_sym, "#{install_location} Pristine".to_sym].each do |loc|
location = local_location(loc)
install_path = File.join(location[:path],install_bundle_name)
next if !options[:force] && bundle_name.nil? && bundle_source(install_path) source ||= fixed_source || get_remote_source(found_bundle_name)
if source.nil?
puts "No matching bundle found for #{found_bundle_name.inspect}"
break
end
if options[:fork] && source[:scm] == :github && github_owner(source) != current_github_user
puts "Forking #{source[:repo]} to #{github_path(current_github_user, source[:file])}"
github_fork source
source[:username] = current_github_user
source[:repo] = github_path(current_github_user, source[:file])
end
puts "Installing #{source[:repo]} to #{install_bundle_name} in #{location[:name]}"
install_bundle(source, install_path)
replacements += 1
end
break unless bundle_name.nil? end
ensure
reload_bundles if replacements > 0
end
|
#install(bundle_name) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
|
# File 'lib/textmate/commands.rb', line 94
def install(bundle_name)
FileUtils.mkdir_p install_bundles_path
puts "Checking out #{bundle_name}..."
installed=false
remote_locations.each do |location|
next unless remote_location(options["source"]) == location if options.key?("source")
name = location[:name]
cmd = case location[:scm]
when :git
'echo "git remotes not implemented yet"'
when :svn
%[svn co "#{location[:path]}/#{url_escape bundle_name}.tmbundle" #{e_sh install_bundles_path}/#{e_sh bundle_name}.tmbundle 2>&1]
when :github
repos = find_github_bundles(location, denormalize_github_repo_name(bundle_name))
case repos.size
when 0
'echo "Sorry, no such bundle found"'
when 1
git_clone(repos.first[:username], repos.first[:name])
else
puts "Multiple bundles with that name found. Please choose which one you want to install:"
repos.each_with_index {|repo, idx|
puts "%d: %s by %s" %
[
idx + 1,
normalize_github_repo_name(repo[:name]),
repo[:username]
]
}
print "Your choice: "
choice = Integer(STDIN.gets.chomp) rescue nil
until choice && (0...repos.size).include?( choice - 1 ) do
print "Sorry, invalid choice. Please enter a valid number or Ctrl+C to stop: "
choice = Integer(STDIN.gets.chomp) rescue nil
end
git_clone(repos[choice - 1][:username], repos[choice - 1][:name])
end
end
res = %x{#{cmd}}
puts cmd, res.gsub(/^/,' ')
installed=true and break if res =~ /Checked out revision|Initialized empty Git repository/
end
abort 'Not Installed' unless installed
reload :verbose => true
end
|
#list(search_term = "") ⇒ Object
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
85
86
|
# File 'lib/textmate/commands.rb', line 48
def list(search_term = "")
search_term = options[:exact] ? Regexp.new("^#{Regexp.escape(search_term)}$") : Regexp.new(search_term, "i")
rows = []
rows << (options[:status] ? %w{Location Bundle SCM Status Source} : %w{Location Bundle}) if options[:flat]
local_locations.each do |bundles_definition|
name = bundles_definition[:name]
bundles_path = bundles_definition[:path]
installed_bundles = get_local_bundles(bundles_path).map {|x| x.split("/").last.split(".").first}.
select {|x| x =~ search_term}
if installed_bundles.size > 0
unless options[:flat]
banner = name.to_s << " Bundles [#{bundles_path}]"
puts "\n" << banner << "\n" << banner.to_s.gsub(/./,'-')
end
if options[:status]
table = []
table << %w{Name SCM Status Source} unless options[:flat]
table += installed_bundles.map do |bundle|
path = File.join(bundles_path, bundle + '.tmbundle')
status = bundle_status(path)
row = [bundle, status[:scm] ? status[:scm].to_s : '-', status[:status] ? status[:status].to_s : '-',
status[:source] ? status[:source].to_s : '-' ]
row.unshift name.to_s if options[:flat]
row
end
if options[:flat]
rows += table
else
print_table table
end
elsif options[:flat]
rows += installed_bundles.map {|b| [name.to_s, b]}
else
puts installed_bundles.join("\n")
end
end
end
print_table rows, :separator=>" | " if options[:flat] && rows.size > 1
end
|
#locations ⇒ Object
221
222
223
224
225
|
# File 'lib/textmate/commands.rb', line 221
def locations
remote_repos = remote_locations.map {|l| ['Remote', l[:short].to_s, l[:name].to_s, l[:path]]}
local_repos = local_locations.map {|l| ['Local', l[:short].to_s, l[:name].to_s, l[:path]]}
print_table([%w{Zone Short Name Location}] + local_repos + remote_repos)
end
|
#register(name, path) ⇒ Object
194
195
196
197
198
199
200
201
|
# File 'lib/textmate/commands.rb', line 194
def register(name, path)
short = options[:short] || name.to_s.downcase.gsub(/\s/,'_')
scm = options[:scm] || :git
abort "Unknown Bundle repository type #{options[:scm]}. Should be #{VALID_SCM_TYPES.join(', ')}" unless
VALID_SCM_TYPES.include?(scm.to_s)
add_remote_location(name, short, scm, path)
save_remote_locations
end
|
#reload(opts = {}) ⇒ Object
214
215
216
217
218
|
# File 'lib/textmate/commands.rb', line 214
def reload(opts = {})
puts "Reloading bundles..." if opts[:verbose]
reload_bundles
puts "Done." if opts[:verbose]
end
|
#search(search_term = "") ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/textmate/commands.rb', line 23
def search(search_term = "")
search_term = Regexp.new(".*#{search_term}.*", "i")
bundles_by_source = {}
each_remote_bundle(search_term) do |location|
name = location[:name]
bundles_by_source[name] ||= {:name=>name, :path=>location[:path], :bundles=>[]}
bundles_by_source[name][:bundles] << location
end
each_remote_source do |source|
name = source[:name]
next unless v=bundles_by_source[name]
banner = name.to_s << " Remote Bundles [#{v[:path]}]"
puts "\n" << banner << "\n" << banner.to_s.gsub(/./,'-')
v[:bundles].each do |b|
s = b[:file].sub(/[-\.]?tmbundle\/?$/i,'')
s << " (by #{b[:username]})" if b[:username]
puts s
end
end
end
|
#uninstall(bundle_name) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/textmate/commands.rb', line 153
def uninstall(bundle_name)
removed = false
puts "Removing bundle..."
each_local_bundle do |bundle_path|
next unless File.basename(bundle_path, '.*') == bundle_name
removed = true
%x[osascript -e 'tell application "Finder" to move the POSIX file "#{bundle_path}" to trash']
break
end
unless removed
say "There is no bundle #{bundle_name} in the system", :red
exit
else
reload :verbose => true
end
end
|
#unregister(name) ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/textmate/commands.rb', line 204
def unregister(name)
if remove_remote_location(name)
save_remote_locations
else
abort "Location #{name} not found"
end
end
|
#update ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/textmate/commands.rb', line 176
def update
each_local_bundle do |path|
svn_path = File.join(path, ".svn")
github_path = File.join(path, ".git")
if File.exist?(github_path)
puts "Updating #{path}"
%x[git --git-dir=#{e_sh github_path} --work-tree=#{e_sh path}pull]
elsif File.exist?(svn_path)
puts "Updating #{path}"
%x[svn up #{e_sh path}]
end
end
end
|