-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: git blame input (Fixes #199)
- Loading branch information
James Brundage
committed
Nov 4, 2023
1 parent
5733a4c
commit 4223d0c
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<# | ||
.SYNOPSIS | ||
Extends git blame's parameters | ||
.DESCRIPTION | ||
Extends the parameters for git blame. | ||
#> | ||
[ValidatePattern('^git blame')] | ||
[Management.Automation.Cmdlet("Use","Git")] | ||
[CmdletBinding(PositionalBinding=$false)] | ||
param( | ||
# The line number (and relative offset) | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[int[]] | ||
$LineNumber, | ||
|
||
# The blame pattern to look for. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string[]] | ||
$Pattern | ||
) | ||
|
||
process { | ||
|
||
# All git of these git blame parameters need to be after the input object: | ||
foreach ($gitArgToBe in @( | ||
if ($LineNumber) { # If a -LineNumber was provided | ||
# turn each pair into a range | ||
for ($LineNumberNumber = 0; $LineNumberNumber -lt $LineNumber.Length; $LineNumberNumber++) { | ||
"-L" # (this will be specified by git blame's real parameter, '-L') | ||
"$( | ||
if ($LineNumberNumber -lt ($LineNumber.Length - 1)) { | ||
"$($lineNumber[$LineNumberNumber]),$($lineNumber[$LineNumberNumber + 1])" | ||
} else { | ||
# if there was only one of a pair, only grab that line. | ||
"$($lineNumber[$LineNumberNumber]),1" | ||
} | ||
)" | ||
} | ||
} | ||
|
||
if ($Pattern) { # If a -Pattern was provided | ||
foreach ($linePattern in $pattern) { | ||
"-L" # this also becomes '-L' in git blame | ||
"$linePattern" | ||
} | ||
} | ||
)) { | ||
$gitArgToBe | Add-Member NoteProperty AfterInput $true -Force -PassThru | ||
} | ||
} |