Class: Rprompt::GitTrack

Inherits:
PromptItem show all
Defined in:
lib/rprompt.rb

Instance Attribute Summary

Attributes inherited from PromptItem

#color, #symbol

Instance Method Summary collapse

Methods inherited from PromptItem

#commandResult

Methods included from Deco

#termShow

Constructor Details

#initialize(config, state) ⇒ GitTrack

Returns a new instance of GitTrack.

Parameters:

  • state (Symbol)

    (“ahead” or “behind”)

  • config (Hash)

    Prompt item configuration:

    • :cmd => shell command

    • :symbol => character

    • :color => color name



67
68
69
70
# File 'lib/rprompt.rb', line 67

def initialize(config, state)
	@state = state
	super(config)
end

Instance Method Details

#countInteger

Note:

works only if remote branch is tracked

Returns number of commits ahead or behind remote.

Returns:

  • (Integer)

    number of commits ahead or behind remote



74
75
76
77
# File 'lib/rprompt.rb', line 74

def count
	commandResult.match(/#{@state}\s+([0-9]+)/)
	$1.to_i
end

#showString

Returns terminal representation of the tracking.

Returns:

  • (String)

    terminal representation of the tracking



80
81
82
# File 'lib/rprompt.rb', line 80

def show
	count != 0 ? termShow({:color => color, :symbol => symbol, :content => count}) : ''
end