From ee6a75de9a199dc03f930f381c49a9340b7e9710 Mon Sep 17 00:00:00 2001 From: PrincessPi Date: Thu, 30 Jul 2026 14:40:40 -0600 Subject: [PATCH] added match.ps1 to Windows-Scripts to make quick strcmps easier in powershell --- Windows-Scripts/match.ps1 | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Windows-Scripts/match.ps1 diff --git a/Windows-Scripts/match.ps1 b/Windows-Scripts/match.ps1 new file mode 100644 index 0000000..acf8133 --- /dev/null +++ b/Windows-Scripts/match.ps1 @@ -0,0 +1,99 @@ +[CmdletBinding()] +param( + # First string to compare + [Parameter(Position = 0)] + [string]$String1, + + # Second string to compare + [Parameter(Position = 1)] + [string]$String2, + + # Optional switch to enable case-sensitive comparison + [switch]$CaseSensitive, + + # Help flag (-h, -Help) + [Alias('h')] + [switch]$Help +) + +begin { + function Show-Help { + @' +NAME + match - Compare two strings and output visual match status + +SYNOPSIS + match [-CaseSensitive] + match -Help + +DESCRIPTION + Compares two string arguments. + Outputs "Match OK" in GREEN if they match. + Outputs "FAIL: NO MATCH" in RED if they differ. + +PARAMETERS + String1 + The first string to compare. + + String2 + The second string to compare. + + -CaseSensitive + Perform a case-sensitive comparison (default is case-insensitive). + + -h, -Help, h, help (case insensitive) + Display this help message. + +EXAMPLES + 1. Compare two strings (case-insensitive default): + match "hello" "Hello" + Output: Match OK (in green) + + 2. Compare two strings with case sensitivity: + match "hello" "Hello" -CaseSensitive + Output: FAIL: NO MATCH (in red) + + 3. Compare hashes or checksum outputs: + match "e3b0c442" "e3b0c442" + Output: Match OK (in green) +'@ + } +} + +process { + # Check if help was explicitly requested via flag or positional parameter + $isHelpRequested = $Help.IsPresent -or ( + $PSBoundParameters.Count -gt 0 -and ( + ($String1 -and $String1 -match '^(?i)[-/]{0,2}(h|help)$') -or + ($String2 -and $String2 -match '^(?i)[-/]{0,2}(h|help)$') + ) + ) + + if ($isHelpRequested) { + Show-Help + return + } + + # Trigger help usage if either string parameter is missing or whitespace + if ([string]::IsNullOrWhiteSpace($String1) -or [string]::IsNullOrWhiteSpace($String2)) { + Write-Host "Error: Missing required arguments." -ForegroundColor Yellow + Write-Host "Usage: match [-CaseSensitive]" -ForegroundColor Cyan + Write-Host "Run 'match -Help' for detailed documentation.`n" + return + } + + # Compare strings based on case-sensitivity choice + $isMatch = if ($CaseSensitive) { + $String1 -ceq $String2 + } else { + $String1 -eq $String2 + } + + if ($isMatch) { + Write-Host "`n`nSUCCESS: MATCH OK!`n`n" -ForegroundColor Green + } else { + Write-Host "`n`nFAIL: NO MATCH!`n`n" -ForegroundColor Red + } +} + +end {} \ No newline at end of file