tmb 0.0.95 → 0.0.96

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.
data/Rakefile CHANGED
@@ -4,13 +4,14 @@ require 'echoe'
4
4
  #Echoe.new(File.basename(File.dirname(__FILE__)))
5
5
 
6
6
  App = "tmb"
7
- Version = "0.0.95"
7
+ Version = "0.0.96"
8
8
 
9
9
  Echoe.new(App, Version) do |p|
10
10
  p.name = App
11
11
  p.version = Version
12
12
  p.author = "Justin Thibault"
13
13
  p.email = "jvthibault@gmail.com"
14
+ p.runtime_dependencies = ['json' ]
14
15
  p.bin_files = ["tmb"]
15
16
 
16
17
  p.install_message = <<-eos
@@ -1,10 +1,14 @@
1
+ require 'fileutils'
1
2
  module TM
3
+
4
+ include FileUtils
2
5
 
3
6
  TextWrap = 78
4
7
  IndentSpacing = 10
5
8
  Indent = (" " * IndentSpacing)
6
9
  Justify = 15
7
10
  Delimiter = ": "
11
+ BundleListPrefix = " * "
8
12
  BaseBundleDirectory = "/Library/Application Support/TextMate/Bundles"
9
13
  UserBundleDirectory = "#{ENV['HOME']}/Library/Application Support/TextMate/Bundles"
10
14
  `mkdir -p "#{TM::UserBundleDirectory}"`
@@ -54,6 +58,13 @@ module TM
54
58
  # you'd like to destroy
55
59
 
56
60
  \033[1m#{App} uninstall json\033[0m
61
+
62
+ # Update bundle named 'json' if we can find it in your installation records.
63
+ # If we can't find a record, we will attempt to run the normal installation routine
64
+ # for the bundle name you entered. If #{App} has degenerate records, you will still
65
+ # have the option to overwrite the existing version during the normal install process.
66
+
67
+ \033[1m#{App} update json\033[0m
57
68
 
58
69
 
59
70
  # Tell textmate (if it's open) to reload its bundle information,
@@ -110,9 +121,18 @@ module TM
110
121
  end
111
122
 
112
123
  def initialize(result=nil, options={})
113
- @before_hooks = @result = result
114
- @repository = options[:repo] || git_repo
115
- before(:git_install_script, :update_db)
124
+ if result.nil?
125
+ @repository = options[:repo]
126
+ @result = {
127
+ "name" => self.class.name_from_repo(@repository),
128
+ "bundle_name" => options[:bundle_name],
129
+ "url" => @repository
130
+ }
131
+ else
132
+ @before_hooks = @result = result
133
+ @repository = git_repo
134
+ end
135
+ #before(:git_install_script, :update_db)
116
136
  end
117
137
 
118
138
  def self.installed
@@ -122,25 +142,46 @@ module TM
122
142
  def self.db_filename
123
143
  File.join(SettingsDirectory, DB)
124
144
  end
145
+
146
+ def self.existing_installdb
147
+ ( YAML.load File.read( self.db_filename ) rescue nil ) || {}
148
+ end
125
149
 
126
150
  def self.db(settings=nil)
151
+ #puts "with settings...#{settings.inspect}"
152
+ if !File.exist?(db_filename)
153
+ puts "DB doesn't exist (#{db_filename}). Skipping addition of bundle to install db."
154
+ return
155
+ end
127
156
  f = File.open(db_filename,File::RDWR|File::CREAT)
128
- unless settings.nil? or settings.class.name =~ /^Hash/
129
- parsed = settings.merge(YAML::parse( f.read ) || {})
157
+ unless settings.nil? or !( settings.class.name =~ /^Hash/ )
158
+ parsed = settings.merge self.existing_installdb
130
159
  f.puts YAML::dump( parsed )
131
160
  end
132
161
  db_content = f.read
133
162
  f.close
134
- YAML::parse( db_content )
163
+ self.existing_installdb
135
164
  end
136
165
 
137
166
  def self.info
138
167
  File.read(db_filename)
139
168
  end
169
+
170
+ def self.installed_bundle_filenames
171
+ installed.map do |b|
172
+ File.basename(b)
173
+ end
174
+ end
175
+
176
+ def self.installed_bundle_titles
177
+ installed.map do |b|
178
+ TM::BundleListPrefix + File.basename(b).gsub(/\.tmbundle$/,'')
179
+ end
180
+ end
140
181
 
141
182
  def self.list
142
183
  installed.each do |b|
143
- puts File.basename(b)
184
+ puts TM::BundleListPrefix + File.basename(b)
144
185
  end
145
186
  end
146
187
 
@@ -149,20 +190,29 @@ module TM
149
190
  end
150
191
 
151
192
  def self.uninstall(bundle)
193
+ if bundle.nil? || bundle == ""
194
+ puts "We couldn't find an appropriate bundle to uninstall...Exiting"
195
+ return
196
+ end
152
197
  bundle_dir = File.basename(bundle)
153
- FileUtils.rm_r(File.join(BundleDirectory, bundle_dir))
198
+ #{}` rm -Rf #{ File.join(BundleDirectory, bundle_dir) }`
199
+ FileUtils.rm_r File.join(BundleDirectory, bundle_dir)
154
200
  end
155
201
 
156
202
  def short_result
157
203
  {:description => result["description"], :repo => repository }
158
204
  end
205
+
206
+ def self.name_from_repo(repository_url)
207
+ repository_url.scan(/(\w\-0-9)\.git$/)
208
+ end
159
209
 
160
210
  def name
161
211
  result["name"] || repository.scan(/(\w\-0-9)\.git$/)
162
212
  end
163
213
 
164
214
  def bundle_name
165
- name.gsub("tmbundle",'').gsub(/^[[:punct:]]+|[[:punct:]]+$/,'')
215
+ result["bundle_name"] || name.gsub("tmbundle",'').gsub(/^[[:punct:]]+|[[:punct:]]+$/,'')
166
216
  end
167
217
 
168
218
  def git_repo
@@ -335,7 +385,14 @@ module TM
335
385
 
336
386
  def hash(digester="sha1")
337
387
  if git_repo?
338
- op = File.read(File.join(destination,".git","refs","heads","master"))
388
+ master_file = File.join(destination,".git","refs","heads","master")
389
+ begin
390
+ op = File.read(master_file)
391
+ rescue => e
392
+ puts "An error occurred while attempting to read #{master_file}...skipping\n #{e.message}"
393
+ `ls "#{ File.dirname(master_file) }"`
394
+ op = ""
395
+ end
339
396
  else
340
397
  op = IO.popen("cat `ls -F #{destination} | grep -v -E '\/$'` | #{digester} | tr '\n' ''").read
341
398
  end
@@ -343,10 +400,11 @@ module TM
343
400
  end
344
401
 
345
402
  def db_hash
346
- { name => {"url" => repository, "dir" => destination, "installed" => Time.now.to_s, "sha1" => hash}}
403
+ { bundle_name => {"url" => repository, "dir" => destination, "installed" => Time.now.to_s, "sha1" => hash}}
347
404
  end
348
405
 
349
406
  def update_db
407
+ puts "Updating install db"
350
408
  self.class.db(db_hash)
351
409
  end
352
410
 
@@ -358,13 +416,13 @@ module TM
358
416
  File.exists?(destination)
359
417
  end
360
418
 
361
- def install
362
- if bundle_exists?
419
+ def install(prompt_on_reinstall=true)
420
+ if bundle_exists? && prompt_on_reinstall
363
421
  puts "That bundle already appears to be installed at #{destination}.\n\nReinstall? [Yn]"
364
422
  answer = STDIN.gets.chomp
365
- return if answer == "n"
423
+ exit if answer == "n"
366
424
  end
367
- puts "Installing from #{@repository}"
425
+ puts "#{prompt_on_reinstall ? 'Installing' : 'Updating bundle'} from #{@repository}"
368
426
  run_script(:git_install_script)
369
427
  puts "Bundle installed to #{destination}. \n\nReloading bundles..."
370
428
  run_script(:bundle_reload_script)
@@ -58,7 +58,7 @@ module TM
58
58
  def self.socket_error(e, url)
59
59
  <<-eos
60
60
 
61
- #LIB is raising a #EXCEPTION: \033[1m#{e.message}\033[0m
61
+ #LIB is raising a #EXCEPTION: \033[0m#{e.message}\033[0m
62
62
 
63
63
  Either \033[1m#HOST\033[0m is currently unavailable or your internet connection is down.
64
64
 
@@ -7,7 +7,8 @@ module TM
7
7
  end
8
8
 
9
9
  def self.run(args)
10
- `mkdir -p #{TM::SettingsDirectory}`
10
+ FileUtils.mkdir_p TM::SettingsDirectory unless File.exist?(TM::SettingsDirectory)
11
+ #`mkdir -p #{TM::SettingsDirectory}`
11
12
  `touch #{TM::Bundles.searchdb_file}`
12
13
  if args[0].nil?
13
14
  help
@@ -34,17 +35,47 @@ module TM
34
35
  print "\n\nMake your selection: "
35
36
  selection = STDIN.gets.chomp
36
37
  result = results[selection.to_i - 1]
37
-
38
- else
38
+ elsif results.size == 1
39
39
  result = results.first
40
+ else
41
+ puts "There are no bundles matching #{args[1].bold}"
42
+ remaining = TM::Bundle.installed_bundle_titles
43
+ if remaining.size > 0
44
+ puts "Here are the bundles installed to #{TM::BundleDirectory.bold}:\n\n"
45
+ self.list
46
+ else
47
+ puts "The bundle directory appears to be completely empty."
48
+ end
49
+ exit 1
50
+ end
51
+ bundle_name = File.basename(result)
52
+ bundle_title = bundle_name.gsub(/\.tmbundle$/,'').bold
53
+ puts "\nThis will uninstall the #{bundle_title} bundle."
54
+ puts "\nThis can't be undone, aside from reinstalling #{bundle_title} with\n\n #{TM::App} install #{bundle_title}\n\n"
55
+ print "Are you sure you want to continue? (Y/n): "
56
+ confirm = STDIN.gets.chomp
57
+ confirm_string = "Y"
58
+ if confirm == confirm_string
59
+ removed = TM::Bundle.uninstall(result)
60
+ puts "#{bundle_title} uninstalled successfully." if removed
61
+ remaining = TM::Bundle.installed_bundle_titles
62
+ if remaining.size > 0
63
+ puts "\nHere are the remaining bundles:\n\n"
64
+ self.list
65
+ else
66
+ puts "There are now no remaining bundles."
67
+ end
68
+ else
69
+ puts "\nExiting uninstall (we were looking for #{confirm_string.bold} as a response, and you typed #{confirm.bold})..."
70
+ puts "The #{bundle_title} bundle remains active."
40
71
  end
41
- puts "\nYou chose #{result}\n\nUninstalling...\n\n"
42
- removed = TM::Bundle.uninstall(result)
43
- puts "#{result} uninstalled" if removed
44
72
  end
45
73
 
46
74
  def self.list(args=nil)
47
- TM::Bundle.list
75
+ TM::Bundle.installed.each do |bundle|
76
+ puts File.basename(bundle).gsub(/\.tmbundle$/,'').ljust(40).bold + " (#{File.basename(bundle)})"
77
+ end
78
+ #TM::Bundle.list
48
79
  end
49
80
 
50
81
  def self.search_remote(args)
@@ -90,6 +121,18 @@ eos
90
121
  def self.local(args=nil)
91
122
  puts File.read(TM::Bundles.searchdb_file)
92
123
  end
124
+
125
+ def self.update(args)
126
+ bundle_name = args[1]
127
+ repo = TM::Bundle.db[bundle_name]["url"] rescue nil
128
+ if repo.nil?
129
+ puts "OOPS!!!! There is no record of installing #{bundle_name}, so updating won't work at this point.\n\n"
130
+ puts "Running a normal install instead and you may overwrite the existing version if we find one..."
131
+ self.install(args)
132
+ else
133
+ TM::Bundle.new( nil, :repo => repo, :bundle_name => bundle_name ).install(false)
134
+ end
135
+ end
93
136
 
94
137
  def self.install(args)
95
138
  if args[1] =~ /^(https|git):\S*\.git$/
@@ -110,11 +153,11 @@ eos
110
153
  bundles.each_with_index do |b,i|
111
154
  puts b.as_selection(i) + (i==0 ? " (default)" : "").bold
112
155
  end
113
- print "\n\nMake your selection (hit enter to choose default #{bundles.first.name.bold}): "
156
+ print "\nMake your selection (hit enter to choose default #{bundles.first.name.bold}): "
114
157
  selection = STDIN.gets.chomp
115
158
  selection = 1 if selection.nil? or selection == ""
116
159
  result = results[selection.to_i - 1]
117
- puts "\nYou chose #{selection}: #{result['name']}\n\nInstalling...\n\n"
160
+ puts "\nYou chose #{selection}: #{result['name']}...\n\n"
118
161
  bundle = TM::Bundle.new(result)
119
162
  bundle.install
120
163
  puts "Bundle installed to #{bundle.destination}"
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "tmb"
5
- s.version = "0.0.95"
5
+ s.version = "0.0.96"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Justin Thibault"]
9
- s.date = "2011-09-01"
9
+ s.date = "2011-09-02"
10
10
  s.description = "tmb provides a command line interface to manage your textmate bundles, allowing you to search for new bundles on github, install them, and uninstall existing local bundles."
11
11
  s.email = "jvthibault@gmail.com"
12
12
  s.executables = ["tmb"]
@@ -24,8 +24,11 @@ Gem::Specification.new do |s|
24
24
  s.specification_version = 3
25
25
 
26
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<json>, [">= 0"])
27
28
  else
29
+ s.add_dependency(%q<json>, [">= 0"])
28
30
  end
29
31
  else
32
+ s.add_dependency(%q<json>, [">= 0"])
30
33
  end
31
34
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 161
4
+ hash: 223
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 95
10
- version: 0.0.95
9
+ - 96
10
+ version: 0.0.96
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Thibault
@@ -15,9 +15,22 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-01 00:00:00 Z
19
- dependencies: []
20
-
18
+ date: 2011-09-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
21
34
  description: tmb provides a command line interface to manage your textmate bundles, allowing you to search for new bundles on github, install them, and uninstall existing local bundles.
22
35
  email: jvthibault@gmail.com
23
36
  executables: