@@ -470,36 +470,45 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) {
470470 }
471471}
472472
473- $PowerTab_RegisterTabExpansion = if (Get-Module - Name powertab) { Get-Command Register-TabExpansion - Module powertab - ErrorAction SilentlyContinue }
474- if ($PowerTab_RegisterTabExpansion ) {
475- & $PowerTab_RegisterTabExpansion " git.exe" - Type Command {
476- param ($Context , [ref ]$TabExpansionHasOutput , [ref ]$QuoteSpaces ) # 1:
473+ if ($PSVersionTable.PSVersion.Major -ge 6 ) {
474+ Register-ArgumentCompleter - CommandName git, tgit, gitk - Native - ScriptBlock {
475+ param ($wordToComplete , $commandAst , $cursorPosition )
477476
478- $line = $Context.Line
479- $lastBlock = [regex ]::Split($line , ' [|;]' )[-1 ].TrimStart()
480- $TabExpansionHasOutput.Value = $true
481- Expand-GitCommand $lastBlock
477+ Expand-GitCommand $commandAst.Extent.Text
482478 }
483- return
484479}
480+ else {
481+ $PowerTab_RegisterTabExpansion = if (Get-Module - Name powertab) { Get-Command Register-TabExpansion - Module powertab - ErrorAction SilentlyContinue }
482+ if ($PowerTab_RegisterTabExpansion ) {
483+ & $PowerTab_RegisterTabExpansion " git.exe" - Type Command {
484+ param ($Context , [ref ]$TabExpansionHasOutput , [ref ]$QuoteSpaces ) # 1:
485485
486- if (Test-Path Function:\TabExpansion) {
487- Rename-Item Function:\TabExpansion TabExpansionBackup
488- }
486+ $line = $Context.Line
487+ $lastBlock = [regex ]::Split($line , ' [|;]' )[-1 ].TrimStart()
488+ $TabExpansionHasOutput.Value = $true
489+ Expand-GitCommand $lastBlock
490+ }
491+ return
492+ }
489493
490- function TabExpansion ($line , $lastWord ) {
491- $lastBlock = [regex ]::Split($line , ' [|;]' )[-1 ].TrimStart()
494+ if (Test-Path Function:\TabExpansion) {
495+ Rename-Item Function:\TabExpansion TabExpansionBackup
496+ }
492497
493- switch - regex ($lastBlock ) {
494- # Execute git tab completion for all git-related commands
495- " ^$ ( Get-AliasPattern git) (.*)" { Expand-GitCommand $lastBlock }
496- " ^$ ( Get-AliasPattern tgit) (.*)" { Expand-GitCommand $lastBlock }
497- " ^$ ( Get-AliasPattern gitk) (.*)" { Expand-GitCommand $lastBlock }
498+ function TabExpansion ($line , $lastWord ) {
499+ $lastBlock = [regex ]::Split($line , ' [|;]' )[-1 ].TrimStart()
498500
499- # Fall back on existing tab expansion
500- default {
501- if (Test-Path Function:\TabExpansionBackup) {
502- TabExpansionBackup $line $lastWord
501+ switch - regex ($lastBlock ) {
502+ # Execute git tab completion for all git-related commands
503+ " ^$ ( Get-AliasPattern git) (.*)" { Expand-GitCommand $lastBlock }
504+ " ^$ ( Get-AliasPattern tgit) (.*)" { Expand-GitCommand $lastBlock }
505+ " ^$ ( Get-AliasPattern gitk) (.*)" { Expand-GitCommand $lastBlock }
506+
507+ # Fall back on existing tab expansion
508+ default {
509+ if (Test-Path Function:\TabExpansionBackup) {
510+ TabExpansionBackup $line $lastWord
511+ }
503512 }
504513 }
505514 }
0 commit comments