From 28b492f2b8685f905d64b72de39599a6b9e84d66 Mon Sep 17 00:00:00 2001 From: dodmi <4572946+dodmi@users.noreply.github.com> Date: Tue, 6 Apr 2021 21:14:40 +0200 Subject: [PATCH] Changed behavior for case git diff: git displays a better help outside of repositories, so execute git in TEMP instead of the current dir --- src/GitHintTabExpansion.ps1 | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/GitHintTabExpansion.ps1 b/src/GitHintTabExpansion.ps1 index c49f1ccdd..9eaeb6c09 100644 --- a/src/GitHintTabExpansion.ps1 +++ b/src/GitHintTabExpansion.ps1 @@ -32,7 +32,7 @@ function Get-GITModeHint { } $script:paramHints.$Command.add("*", $modeTable) } - + # Create the results if ($script:paramHints.$Command."*".containsKey($Mode)) { @@ -62,28 +62,19 @@ function Get-GITParameterHint { if (-not $script:paramHints.containsKey($Command)) { $script:paramHints.add($Command, @{}) } # Populate the "mode branch" if empty if (-not $script:paramHints.$Command.containsKey($Mode)) { - $helpStrings = Invoke-Utf8ConsoleCommand { & $Command $Mode -h 2>&1 } - $exceptions = @("diff") + $helpStrings = Invoke-Utf8ConsoleCommand { & $Command -C "$($env:temp)" --no-pager $Mode -h 2>&1 } $preProcessedStrings = @() # Preprocessing foreach ($line in $helpStrings) { switch -RegEx ($line) { - "^\s{2,2}(-.*)$" { - # this a line defining a parameter, if we are in git diff - if ($Mode -like "diff") { $preProcessedStrings += "$($Matches[1])" } - } - "^\s{15,15}(\s.*)$" { - # this line belongs to the parameter description of the line before in git diff - if ($Mode -like "diff") { $preProcessedStrings[-1] = "$($preProcessedStrings[-1])$($Matches[1])" } - } "^\s{4,4}(-.*)$" { # this is a line defining a parameter - if ($Mode -notin $exceptions) { $preProcessedStrings += "$($Matches[1])" } + $preProcessedStrings += "$($Matches[1])" } "^\s{25,25}(\s.*)$" { # this line belongs to the parameter description of the line before - if ($Mode -notin $exceptions) { $preProcessedStrings[-1] = "$($preProcessedStrings[-1])$($Matches[1])" } + $preProcessedStrings[-1] = "$($preProcessedStrings[-1])$($Matches[1])" } } } @@ -171,7 +162,7 @@ function Add-HintsToParams { # We are only handling git at the moment if ($Command -notmatch "^$(Get-AliasPattern git) (.*)") { return $PossibleParams } - + # Determing git mode, which is the first parameter without dashes, but not the last one, which is "" or an incomplete parameter $cmdMode = $null for ($i=1; $i -lt $cmdParts.length-1; $i++) { @@ -180,7 +171,7 @@ function Add-HintsToParams { break } } - + $newTabCompletions = @() if ($cmdMode) { # we're searching a parameter for mode $cmdMode