-
-
Save kashewnuts/b10d2e1607e6b5a7191d7dcf028de50a to your computer and use it in GitHub Desktop.
A clink script for supporting tab-completion of git branches when using "git checkout", and showing branch name.
This file contains 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
-- [[ | |
-- Git config for clink | |
-- A clink script for supporting tab-completion of git branches when using | |
-- "git checkout", and showing branch name. | |
-- ]] | |
function git_checkout_match_generator(text, first, last) | |
found_matches = false; | |
local line_buffer = rl_state.line_buffer | |
if line_buffer:find("^git checkout ") or | |
line_buffer:find("^git co ") then | |
local lines = io.popen("git branch 2>nul"):lines() | |
for line in lines do | |
local m = line:match("[%* ] (.+)$") | |
if m then | |
has_start_branch = | |
not line_buffer:find("^git checkout[ ]*$") and | |
not line_buffer:find("^git co[ ]*$") | |
if (not has_start_branch) or | |
(#text > 0 and m:find(text)) then | |
clink.add_match(m) | |
found_matches = true; | |
end | |
end | |
end | |
end | |
return found_matches | |
end | |
function git_prompt_filter() | |
local lines = io.popen("git branch 2>nul"):lines() | |
for line in lines do | |
local m = line:match("%* (.+)$") | |
if m then | |
clink.prompt.value = clink.prompt.value.." ["..m.."] " | |
break | |
end | |
end | |
return false | |
end | |
clink.register_match_generator(git_checkout_match_generator, 10) | |
clink.prompt.register_filter(git_prompt_filter, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment