class EnhancedPrompt::Prompt::Token::Git

Public Class Methods

new(dir) click to toggle source
# File lib/enhanced_prompt/token/git.rb, line 5
def initialize(dir)
  @dir = dir
end

Public Instance Methods

git(prefix:'(',suffix:')') click to toggle source
# File lib/enhanced_prompt/token/git.rb, line 9
def git(prefix:'(',suffix:')')
  _call_git_branch
end

Private Instance Methods

_call_git_branch() click to toggle source

TODO this could not show git branch I should run %x|git branch| in Dir.pwd

# File lib/enhanced_prompt/token/git.rb, line 17
def _call_git_branch
  stdout,stderr,status = *Open3.capture3("cd #{@dir};git branch")
  if stdout =~ /^[*]\s(\w+)/ && status.exitstatus == 0 then
    @_current_branch = $1
  else
    ''
  end
end
_current_branch() click to toggle source
# File lib/enhanced_prompt/token/git.rb, line 26
def _current_branch
  if @_current_branch.nil? then
    begin
      result = %x|cd #{@dir};git branch|
      if result =~ /^[*]\s(\w+)/ then
        @_current_branch = $1
      else
        ''
      end
    rescue =>e
      return ''
    end
  else
    @_current_branch
  end

end