Class: Git::StatusAll::App
- Inherits:
-
Object
- Object
- Git::StatusAll::App
- Defined in:
- lib/git/status_all.rb
Instance Method Summary collapse
Instance Method Details
#file_status(g) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/git/status_all.rb', line 63 def file_status(g) result = "" result += "A#{g.status.added.length}" if g.status.added.length > 0 result += "D#{g.status.deleted.length}" if g.status.deleted.length > 0 result += "M#{g.status.changed.length}" if g.status.changed.length > 0 result += "U#{g.status.untracked.length}" if g.status.untracked.length > 0 return result end |
#main ⇒ Object
12 13 14 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 53 54 55 56 57 58 59 60 61 |
# File 'lib/git/status_all.rb', line 12 def main # we want to disable the text coloring if we are printing to a # file, or on a platform (like windows) that likely doesn't support # the colors String.disable_colorization = !$stdout.isatty opts = Trollop:: do version "git-status-all #{Git::StatusAll::VERSION} (c) 2016 @reednj ([email protected])" "Usage: git-status-all [options] [path]" opt :fetch, "perform fetch for each repository before getting status", :default => false end dev_dir = ARGV.last || '.' repo_paths = Dir.entries(dev_dir). map {|p| { :name => p, :path => File.(p, dev_dir) } }. select { |p| Git.repo? p[:path] } repo_paths.each do |p| name = p[:name] begin g = Git.open p[:path] if opts[:fetch] print "#{name}".right_align("[#{"fetching...".yellow}]") + "\r" if !g.remotes.empty? remote = g.remotes.select{|r| r.name.downcase == 'origin' }.first || g.remotes.first g.fetch remote end end s = file_status(g) r = remote_status(g) s = " #{s} ".black.on_yellow unless s.empty? n = s.empty? ? name : name.yellow puts "#{n}".pad_to_col(24).append(s).right_align("#{r} [#{g.branches.current.to_s.blue}]") rescue => e if e.to_s.include? "ambiguous argument 'HEAD'" err ='ERROR: NO HEAD' else err ='ERROR' end puts "#{name}".right_align("[#{err}]".red) puts e.to_s if err == 'ERROR' end end end |
#remote_status(g) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/git/status_all.rb', line 72 def remote_status(g) if g.remotes.empty? return "no remotes".black.on_red end if g.remotes.select{|r| r.name.downcase == 'origin' }.empty? return "no origin".black.on_yellow end if !g.branches[:master].up_to_date? b = g.branches[:master] s = '' s += "#{b.behind_count}\u2193" if b.behind_count > 0 s += "#{b.ahead_count}\u2191" if b.ahead_count > 0 return s.green end return '' end |
#term_width ⇒ Object
94 95 96 |
# File 'lib/git/status_all.rb', line 94 def term_width @term_width ||= `tput cols`.to_i end |