Update PowerShell profile with new custom function

This commit is contained in:
James Skemp 2024-01-24 20:42:02 -06:00
parent ac9a0b9716
commit 75424dfa5e
1 changed files with 22 additions and 0 deletions

View File

@ -33,4 +33,26 @@ Set-Title-Folder sets the window/tab title, such as for Windows Terminal, based
#>
$Host.UI.RawUI.WindowTitle = Split-Path -Path (Get-Location) -Leaf
}
function Start-ExtensionOpen {
<#
.Description
Start-ExtensionOpen opens a single file with a matching extension, if possible.
#>
param(
[string]
$FileExtension
)
$matchingFiles = Get-ChildItem . -Filter *.$FileExtension
$matchCount = ($matchingFiles | Measure-Object).Count
if ($matchCount -eq 1) {
Write-Output "Opening $($matchingFiles.Name)"
Invoke-Item $matchingFiles[0]
} elseif ($matchCount -eq 0) {
Write-Error "No matching files for $($FileExtension)"
} else {
Write-Output $matchingFiles.Name
}
}
```