Public/Add-GitFile.ps1
using namespace System.Collections.Generic function Add-GitFile { [CmdletBinding()] param ( [Parameter(Position = 0)] [ValidateNotNullOrEmpty()] [string[]]$Path = '*', [switch]$Patch ) $AddArgs = [List[string]]::new() $AddArgs.Add('add') if ($Patch) { $AddArgs.Add('--patch') } $AddArgs.AddRange($Path) git $AddArgs $DiffOutput = git diff --cached --color=always $DiffOutput = @($DiffOutput) -notmatch '^(\u001b.*)?(index |--- |\+\+\+ )' -replace '@@ [\-\+\d\,\ ]+ @@' -replace '^(\u001b.*)?diff --git ', "`n`$1" if (-not $DiffOutput) {return} if ($DiffOutput.Count -lt 40) {$DiffOutput} git diff --cached --color=always --compact-summary } Register-ArgumentCompleter -CommandName Add-GitFile -ParameterName Path -ScriptBlock { param ($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) @(git status -s) -replace '^...' -like "*$wordToComplete*" } |