promptula 0.0.5 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/promptula/version.rb +1 -1
  2. data/lib/promptula.rb +31 -22
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module Promptula
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/promptula.rb CHANGED
@@ -21,31 +21,40 @@ module Promptula
21
21
  end
22
22
 
23
23
  def self.git()
24
- branch = `git rev-parse --abbrev-ref HEAD 2>/dev/null`.chomp
25
- branch.split("\n").each do |line|
26
- if line[0] == '*'
27
- branch = line.sub('*', '').chomp
24
+ if system 'git status > /dev/null 2>/dev/null'
25
+ branch = `git rev-parse --abbrev-ref HEAD`.chomp
26
+ branch.split("\n").each do |line|
27
+ if line[0] == '*'
28
+ branch = line.sub('*', '').chomp
29
+ end
28
30
  end
29
- end
30
- remote = `git config branch.#{branch}.remote`.strip
31
- status = `git status --ignore-submodules --porcelain 2>/dev/null`
32
- untracked = (status.match('\?\?') or '').size > 0 ? " #{GLYPH}" : ''
33
- dirty = status.size > 0
34
- background = dirty ? :red : :green
35
- push_pull = `git rev-list --left-right remotes/#{remote}/#{branch}...HEAD`.split("\n")
36
- to_push = (push_pull.select {|m| m.start_with? '>'}).length
37
- to_pull = (push_pull.select {|m| m.start_with? '<'}).length
31
+ tracking = Hash[`git for-each-ref --format='%(refname:short) %(upstream:short)' refs/heads`
32
+ .split("\n")
33
+ .map {|l| l.split ' '}]
38
34
 
39
- prompt = SEPARATOR.foreground(background).background(BACKGROUND).inverse
40
- prompt += "#{branch}#{untracked} ".background(background)
41
- if to_pull > 0
42
- prompt += "#{PULL_ARROW}#{to_pull} ".background(background)
43
- end
44
- if to_push > 0
45
- prompt += "#{PUSH_ARROW}#{to_push} ".background(background)
35
+ status = `git status --ignore-submodules --porcelain`
36
+ untracked = (status.match('\?\?') or '').size > 0 ? " #{GLYPH}" : ''
37
+ dirty = status.size > 0
38
+ background = dirty ? :red : :green
39
+ prompt = SEPARATOR.foreground(background).background(BACKGROUND).inverse
40
+ prompt += "#{branch}#{untracked} ".background(background)
41
+ remote = tracking[branch]
42
+ if remote
43
+ push_pull = `git rev-list --left-right #{remote}...HEAD`.split("\n")
44
+ to_push = (push_pull.select {|m| m.start_with? '>'}).length
45
+ to_pull = (push_pull.select {|m| m.start_with? '<'}).length
46
+ if to_pull > 0
47
+ prompt += "#{PULL_ARROW}#{to_pull} ".background(background)
48
+ end
49
+ if to_push > 0
50
+ prompt += "#{PUSH_ARROW}#{to_push} ".background(background)
51
+ end
52
+ end
53
+ prompt += SEPARATOR.foreground(background).reset()
54
+ prompt
55
+ else
56
+ ''
46
57
  end
47
- prompt += SEPARATOR.foreground(background).reset()
48
- prompt
49
58
  end
50
59
 
51
60
  def self.prompt()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promptula
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop