dahlbyk / posh-git

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

Tab competition: tab vs right arrow #934

Open matys1 opened 1 year ago

matys1 commented 1 year ago

System Details

Issue Description

I'm confused by the behavior of pressing tab key for tab completion. Two examples:

First: I type in git st and the autocomplete suggestion is git status. I press tab and it completes it as git stash. I then have to press tab again to cycle and get git status, the command that was initially suggested and the one that I needed.

Two: I type in git co and the autocomplete suggestion is git commit -am "amended docs" based on my historic commits. I press tab as I want to repeat the same command again and it completes to git checkout.

However, in both examples, if I were to press right arrow instead of tab, it would complete the suggested command in full as suggested and as expected. What's the logic behind the tab command? How can I configure so the tab functions like the right arrow?

mrkaarel commented 1 year ago

The suggestions you are seeing as you type, are not provided by posh-git but by PowerShell PSReadLine module. These work in all directories, not only inside git repositories.

When you press tab key, you are getting posh-git autocompletion. When you press right arrow, you'll get PSReadLine autocompletion.

If this is confusing, you can turn off PSReadLine inline suggestions. Maybe sometimes in the future posh-git will have a auto-completion plugin that is compatible with PSReadLine.

matys1 commented 1 year ago

@mrkaarel Thank you very much, you've given me enough information to make the changes I needed. I ended up moving PSReadLine's AcceptSuggestion to Tab and AcceptNextSuggestionWord to RightArrow in effect overriding posh-git's tab completion completely as my preference was to use PSReadLine. Not sure if there's a proper way to disable posh-git's tab completion via ps1 profile settings though? Either way this works for me now.

vegar commented 1 year ago

@matys1 , Be aware, though, that PSReadLine's suggestions comes from your history, not from the current context. So while it will suggest co to be commit, it will not be able to suggest what file to add based on your modified files. I'll also question how useful history based auto suggestion is for 'git commit' - how often do you reuse the same commit message?

vito-mohagheghian commented 1 year ago

The suggestions you are seeing as you type, are not provided by posh-git but by PowerShell PSReadLine module. These work in all directories, not only inside git repositories.

When you press tab key, you are getting posh-git autocompletion. When you press right arrow, you'll get PSReadLine autocompletion.

If this is confusing, you can turn off PSReadLine inline suggestions. Maybe sometimes in the future posh-git will have a auto-completion plugin that is compatible with PSReadLine.

how can we change the inline suggestion from arrow right to tab?

vegar commented 1 year ago

Take a look at the readme for PSReadLine:

To view the current key bindings:

Get-PSReadLineKeyHandler

To set your own custom keybindings, use the cmdlet Set-PSReadLineKeyHandler. For example, for a better history experience, try:

Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

If you combinde that with @matys1 reply a little further up, I'm sure you'll reach your goal :-)