Skip to content

Commit

Permalink
Changed behavior for case git diff: git displays a better help outsid…
Browse files Browse the repository at this point in the history
…e of repositories, so execute git in TEMP instead of the current dir
  • Loading branch information
dodmi committed Apr 6, 2021
1 parent a1d45c7 commit 28b492f
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/GitHintTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Get-GITModeHint {
}
$script:paramHints.$Command.add("*", $modeTable)
}

# Create the results
if ($script:paramHints.$Command."*".containsKey($Mode))
{
Expand Down Expand Up @@ -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])"
}
}
}
Expand Down Expand Up @@ -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++) {
Expand All @@ -180,7 +171,7 @@ function Add-HintsToParams {
break
}
}

$newTabCompletions = @()
if ($cmdMode) {
# we're searching a parameter for mode $cmdMode
Expand Down

0 comments on commit 28b492f

Please sign in to comment.