Class: TMBundle
- Inherits:
-
Thor
show all
- Defined in:
- lib/tmbundle.rb
Defined Under Namespace
Classes: Bundle, BundleName, BundlesList, NotFound
Instance Method Summary
collapse
Instance Method Details
#cd(partial_name) ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/tmbundle.rb', line 119
def cd(partial_name)
bundle = find_bundle(partial_name)
within bundle do
term_program = ENV['TERM_PROGRAM'] || 'Terminal.app'
system 'open', bundle.path, '-a', term_program
end
end
|
#edit(partial_name) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/tmbundle.rb', line 7
def edit partial_name
bundle = find_bundle(partial_name)
mate bundle.path
rescue NotFound
return false
end
|
#install(name) ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/tmbundle.rb', line 55
def install name
require 'tmbundle/bundle_name'
name = BundleName.new(name)
install_path = bundles_dir.join(name.install_name).to_s
success = system('git', 'clone', name.git_url, install_path)
if not success
puts "attempting clone of #{name.alt_git_url}"
success = system('git', 'clone', name.alt_git_url, install_path)
end
end
|
#list ⇒ Object
112
113
114
115
116
|
# File 'lib/tmbundle.rb', line 112
def list
bundles_list.all.each do |bundle|
puts "- #{bundle.name.ljust(30)} (#{bundle.path})"
end
end
|
#path(name) ⇒ Object
67
68
69
70
71
|
# File 'lib/tmbundle.rb', line 67
def path name
puts find_bundle(name).path
rescue NotFound
return false
end
|
#status(name = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/tmbundle.rb', line 74
def status name = nil
justification = 50
bundles_list.all.each do |bundle|
within bundle do
print "- #{bundle.name}...".ljust(justification)
`git fetch -aq 2> /dev/null`
fetch_successful = $?.success?
branch_info, *changes = `git status -zb`.split("\0")
branch, remote, branch_status, = branch_info.scan(/^## (\S+)\.\.\.(\S+)(?: \[(.+)\])?/).flatten
cd_hint = false
if changes.any?
cd_hint = true
print "✘ #{changes.size} changed/new file#{:s if changes.size != 0}.".ljust(justification)
else
case branch_status.to_s
when /^ahead (\d+)/
ahead_commits = $1
cd_hint = true
print "✘ #{ahead_commits} commits ahead of #{remote}. ".ljust(justification)
when /^behind (\d+)/
behind_commits = $1
cd_hint = true
print "❍ behind remote (#{remote}) by #{behind_commits}. ".ljust(justification)
else
print "✔︎ up-to-date"
end
end
print "$ cd \"#{bundle.path}\" # to enter the bundle directory" if cd_hint
puts
puts "#{' '*justification}✘✘✘ Something went wrong while fetching from remote #{remote}" unless fetch_successful
end
end
end
|
#update(partial_name = nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/tmbundle.rb', line 15
def update(partial_name = nil)
bundle = find_bundle(partial_name) if partial_name
bundles_to_update = bundle ? [bundle] : installed_bundles
require 'thread'
signals = Queue.new
trap('INT') { signals << :int }
updated = []
skipped = []
errored = []
bundles_to_update.each do |bundle|
within bundle do
if not(File.exist?('./.git'))
puts "------> Skipping #{bundle.name} (not a Git repo, delta bundle?)"
skipped << bundle
next
end
puts "------> Updating #{bundle.name}..."
system(*%w[git pull --ff-only])
success = $? == 0
updated << bundle if success
errored << bundle unless success
puts
(puts 'Exiting…'; exit) if signals.pop == :int until signals.empty?
end
end
puts
puts
puts '------> Summary'
puts
puts "Skipped (#{skipped.size})\n- #{skipped.map(&:name).join("\n- ")}\n\n" if skipped.any?
puts "Updated (#{updated.size})\n- #{updated.map(&:name).join("\n- ")}\n\n" if updated.any?
puts "Errored (#{errored.size})\n- #{errored.map(&:name).join("\n- ")}\n\n" if errored.any?
end
|