Skip to content

Instantly share code, notes, and snippets.

@vladimir-kotikov
Created January 7, 2016 18:33
Show Gist options
  • Save vladimir-kotikov/ef164c3baa8b80bd30b0 to your computer and use it in GitHub Desktop.
Save vladimir-kotikov/ef164c3baa8b80bd30b0 to your computer and use it in GitHub Desktop.
function git_prompt_filter_new()
local start_filter = os.clock()
-- Colors for git status
local colors = {
clean = "\x1b[1;37;40m",
dirty = "\x1b[31;1m",
}
local git_info = {}
local proc = io.popen("git rev-parse --git-dir --short --abbrev-ref HEAD 2>nul")
if proc then
for line in proc:lines() do
table.insert(git_info, line)
end
proc:close()
end
if #git_info == 0 then
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "")
print(string.format("elapsed time: %.2f", os.clock() - start_filter))
return false
end
local branch = git_info[2]
local color = get_git_status() and colors.clean or colors.dirty
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")")
print(string.format("elapsed time: %.2f", os.clock() - start_filter))
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment