-
-
Save garyyau/92cd2dc4d4327c230d59 to your computer and use it in GitHub Desktop.
A clink script for supporting tab-completion of git branches when using "git checkout"
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 git_checkout_match_generator(text, first, last) | |
| found_matches = false; | |
| supported_command = has_command_prefix() | |
| if supported_command then | |
| has_start_branch = not rl_state.line_buffer:find("^git checkout[ ]*$") | |
| for line in io.popen("git branch 2>nul"):lines() do | |
| local m = line:match("[%* ] (.+)$") | |
| if m then | |
| if not has_start_branch then | |
| clink.add_match(m) | |
| found_matches = true; | |
| elseif #text > 0 and m:find(text, 1, true) then | |
| clink.add_match(m) | |
| found_matches = true; | |
| end | |
| end | |
| end | |
| end | |
| return found_matches | |
| end | |
| function has_command_prefix() | |
| if rl_state.line_buffer:find("^git checkout ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git branch %-d ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git fetch ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git merge ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git pull ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git push ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git rebase ") then | |
| return true; | |
| elseif rl_state.line_buffer:find("^git log ") then | |
| return true; | |
| end | |
| return false; | |
| end | |
| clink.register_match_generator(git_checkout_match_generator, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment