Update PowerShell profile with new custom function
This commit is contained in:
parent
ac9a0b9716
commit
75424dfa5e
|
@ -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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue