The *search-repo.ps1* Script =========================== This PowerShell script searches for the given text pattern in a Git repository. Parameters ---------- ```powershell /home/markus/Repos/PowerShell/scripts/search-repo.ps1 [[-textPattern] ] [[-path] ] [] -textPattern Specifies the text pattern to search for Required? false Position? 1 Default value Accept pipeline input? false Accept wildcard characters? false -path Specifies the file path to the local Git repository Required? false Position? 2 Default value "$PWD" Accept pipeline input? false Accept wildcard characters? false [] This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. ``` Example ------- ```powershell PS> ./search-repo.ps1 UFO list-calendar.ps1: Write-Host (" " * 4 * [int](Get-Date $day -uformat %u)) -NoNewLine list-calendar.ps1: $dayOffset = [int](Get-Date -day 1 -month ($month + $i) -year $year -uformat %u) ``` Notes ----- Author: Markus Fleschutz | License: CC0 Related Links ------------- https://github.com/fleschutz/PowerShell Script Content -------------- ```powershell <# .SYNOPSIS Searches for text in a repo .DESCRIPTION This PowerShell script searches for the given text pattern in a Git repository. .PARAMETER textPattern Specifies the text pattern to search for .PARAMETER path Specifies the file path to the local Git repository .EXAMPLE PS> ./search-repo.ps1 UFO list-calendar.ps1: Write-Host (" " * 4 * [int](Get-Date $day -uformat %u)) -NoNewLine list-calendar.ps1: $dayOffset = [int](Get-Date -day 1 -month ($month + $i) -year $year -uformat %u) .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> param([string]$textPattern = "", [string]$path = "$PWD") try { if ($textPattern -eq "" ) { $textPattern = Read-Host "Enter the text pattern, e.g. 'UFO'" } if (-not(Test-Path "$path" -pathType container)) { throw "Can't access Git repository at: $path" } $null = (git --version) if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" } & git -C "$path" grep $textPattern if ($lastExitCode -ne "0") { throw "'git grep' failed with exit code $lastExitCode" } exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 } ``` *(generated by convert-ps2md.ps1 as of 11/20/2024 11:52:00)*