mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-22 07:53:21 +01:00
Added search-repo.ps1
This commit is contained in:
parent
dc7abd6506
commit
2a1123485f
38
scripts/search-repo.ps1
Normal file
38
scripts/search-repo.ps1
Normal file
@ -0,0 +1,38 @@
|
||||
<#
|
||||
.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
|
||||
}
|
Loading…
Reference in New Issue
Block a user