dahlbyk / posh-git

A PowerShell environment for Git
http://dahlbyk.github.io/posh-git/
MIT License
7.69k stars 801 forks source link

Feature request: Improve feature branch tab completen #750

Open jakob-grabner opened 4 years ago

jakob-grabner commented 4 years ago

First, thx for the awesome work, I use this powershell module daily. I would love to see the following feature added.

Assume I have a lot of feature branches, it would be awesome if the tab completion could only complete the branch name until the first occurrence of "/" When I type "fea" and press tab it complete to "feature/first_branch", no I have to delete the "first_branch" part and type "sec" -> tab so it completes to "feature/second_branch"

Would be nice if tab completion would work like: "feat" -tab-> "feature/" "feature/se" -tab-> "feature/second_branch"

I know this is probably not high priority but it would really ease my life as a developer typing this command multiple times per day.

dahlbyk commented 4 years ago

I like this idea. Seems like it would be handy for remote branches:

o<tab> 👉 origin/ 👉 origin/m<tab> 👉 origin/master

and path completion:

git add s<tab> 👉 git add src/ 👉 git add src/U<tab> 👉 git add src/Utils.ps1

Implementation-wise, I think we could make a generalized Get-UniquePrefix that would handle this for any list of strings. One question I have: should / get special treatment, or should we expand as far as we can uniquely? In other words, would 'feat','feature/one','feature/two' | Get-UniquePrefix expand to 'feat','feature/' or just 'feat'? (Might not know until we can kick the tires.)

lzybkr commented 4 years ago

If you use bash style completion with PSReadLine then that happens for all completions.

Set-PSReadLineKeyHandler -Key Tab -Function Complete
jakob-grabner commented 4 years ago

@lzybkr When I set

Set-PSReadLineKeyHandler -Key Tab -Function Complete

I actually get a exception inside a git repo. Also it is not quite the same since it just prints all options but does not auto expand as long as the suggestion is unique


System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -46.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.Menu.EnsureMenuAndInputIsVisible(IConsole console, Int32 tooltipLineCount)    at Microsoft.PowerShell.PSConsoleReadLine.Menu.DrawMenu(Menu previousMenu)
   at Microsoft.PowerShell.PSConsoleReadLine.PossibleCompletionsImpl(CommandCompletion completions, Boolean menuSelect)    at Microsoft.PowerShell.PSConsoleReadLine.CompleteImpl(Boolean menuSelect)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)```
jakob-grabner commented 4 years ago

I like this idea. Seems like it would be handy for remote branches:

o<tab> 👉 origin/ 👉 origin/m<tab> 👉 origin/master

and path completion:

git add s<tab> 👉 git add src/ 👉 git add src/U<tab> 👉 git add src/Utils.ps1

Implementation-wise, I think we could make a generalized Get-UniquePrefix that would handle this for any list of strings. One question I have: should / get special treatment, or should we expand as far as we can uniquely? In other words, would 'feat','feature/one','feature/two' | Get-UniquePrefix expand to 'feat','feature/' or just 'feat'? (Might not know until we can kick the tires.)

I think expanding as far as we can uniquely is a good idea. Imho it is not necessary to give special treatment to /

lzybkr commented 4 years ago

@jakob-grabner - That exception is fixed if you upgrade to the latest version of PSReadLine.

Complete will display the possible completions if the current text is the longest unambiguous completion. If you have not yet typed the longest unambiguous prefix, it will complete to the longest unambiguous prefix.

For example, on my system, if I type Get-AzureRmStr<TAB>, it will complete to Get-AzureRmStreamAnalytics and beep, letting me know there are multiple possible completions. If I hit again, it will display those completions.

If on the other hand I had typed Get-AzureRmSt<TAB> (same as above but without the final r, it beeps immediately because there are other commands starting with Get-AzureRmStorage.

At any rate, this experience is very familiar to most folks on Linux/Mac because this is how bash completion works.