Module: Promptula

Defined in:
lib/promptula.rb,
lib/promptula/version.rb

Constant Summary collapse

SEPARATOR =
"\u25B6"
SEPARATOR_THIN =
"\u276F"
PATH_SEPARATOR =
'/'
BACKGROUND =
"3a3a3a"
GLYPH =
"\u2733"
VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.cwdObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/promptula.rb', line 10

def self.cwd()
  current = Dir.pwd
  home = ENV['HOME']
  ret = ''
  current.sub(home, '~').split('/').each do |segment|
    ret += PATH_SEPARATOR.foreground(:black).background(BACKGROUND) if segment != '~'
    ret += "#{segment}".background BACKGROUND
  end
  ret + ' '.background(BACKGROUND)
end

.gitObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/promptula.rb', line 21

def self.git()
  branch = ''
  `git branch 2>/dev/null`.split("\n").each do |line|
    if line[0] == '*'
      branch = line.sub('*', '').chomp
    end
  end
  status = `git rev-parse --abbrev-ref HEAD 2>/dev/null`
  untracked = (status.match('\?\?') or '').size > 0 ? " #{GLYPH}" : ''
  dirty = status.size > 0
  background = dirty ? :red : :green

  SEPARATOR.foreground(background).background(BACKGROUND).inverse + 
  "#{branch}#{untracked} ".background(background) +
  SEPARATOR.foreground(background).reset()
end

.promptObject



38
39
40
41
# File 'lib/promptula.rb', line 38

def self.prompt()
  Sickill::Rainbow.enabled = true
  cwd() + git()
end