Created
May 15, 2015 15:30
-
-
Save rcapraro/1b8003002ee47caa4b12 to your computer and use it in GitHub Desktop.
Git-aware prompt for NYAGOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set{ | |
PROMPT='$e[36;40;1m$P$e[37;1m' | |
} | |
local git_branch = function() | |
local path = nyagos.getwd() | |
repeat | |
if nyagos.access(nyagos.pathjoin(path, '.git'), 0) then | |
break | |
end | |
path = string.match(path, '^(.+)\\') | |
until not path | |
if path then | |
local branch = string.match(nyagos.eval('git branch'), '* ([%S ]*)') | |
if branch then | |
local ref = string.match(branch, '^%(detached from ([0-9a-f]+)%)$') | |
if ref then | |
return '(' .. ref .. '...)' | |
else | |
return branch | |
end | |
else | |
return ('no branch') | |
end | |
else | |
return nil | |
end | |
end | |
local prompt_ = nyagos.prompt | |
nyagos.prompt = function(prompt) | |
local branch = git_branch() | |
if branch then | |
branch = '$e[33;40;1m(' .. branch .. ')$e[37;1m' | |
else | |
branch = '' | |
end | |
return prompt_(prompt .. ' ' .. branch .. '$ ') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment