Last active
September 26, 2021 14:14
-
-
Save maple3142/e553226d697e75c34518f3ca7fabec9e to your computer and use it in GitHub Desktop.
clink show git branch
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
function show_git_branch() | |
for line in io.popen("git branch 2>nul"):lines() do | |
local m = line:match("%* (.+)$") | |
local b = "\x1b[32;22;49m".."("..m..")".."\x1b[39;22;49m" | |
if m then | |
clink.prompt.value = clink.prompt.value:gsub(">"," "..b.." >") | |
break | |
end | |
end | |
return false | |
end | |
clink.prompt.register_filter(show_git_branch, 50) |
@zodman Nice work. For me a small modification was necessary because I was running into the following issue:
clink.lua:3435: attempt to concatenate local 'm' (a nil value)
I think it should be (at least that works for me):
function show_git_branch()
for line in io.popen("git branch 2>nul"):lines() do
local m = line:match("%* (.+)$")
if m then
local b = "\x1b[32;22;49m".."("..m..")".."\x1b[39;22;49m"
clink.prompt.value = clink.prompt.value:gsub(">"," "..b.." >")
break
end
end
return false
end
clink.prompt.register_filter(show_git_branch, 50)
@keocra your code works!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@zodman Go to your clink installation dir and find
clink.lua
, then paste this code at the bottom.