Skip to content

Commit 1327af9

Browse files
committed
fix: more flexible choice for show-window
1 parent cdd2ae4 commit 1327af9

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

quickPwshUtils.psm1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,20 @@ function Show-Window {
2727
[string] $ProcessName
2828
)
2929
$ProcessName = $ProcessName -replace '\.exe$'
30-
# WARN: This method return the latest windows which have title. many have titles but cant show.
31-
# IF you want to switch between them, must use different method like powertoys run.
32-
$procId = (Get-Process -ErrorAction Ignore "*$ProcessName*"
33-
).Where({ $_.MainWindowTitle }, 'First').Id
3430

31+
$b = (Get-Process -ErrorAction Ignore "*$ProcessName*").Where({ $_.MainWindowTitle })
32+
$c = $b | % ProcessName | fzf --select-1 --exit-0 --bind one:accept | %{$b | ? Name -eq $_}
33+
$procId = $c.ID
3534
if (-not $procId) {
3635
throw "No $ProcessName process with a non-empty window title found."
3736
return 1
3837
}
39-
$null = (New-Object -ComObject WScript.Shell).AppActivate($procId)
38+
return (New-Object -ComObject WScript.Shell).AppActivate($procId)
4039
}
41-
Set-Alias -Name shw -Value Show-Window
40+
4241
# Load the necessary assembly
4342
Add-Type -AssemblyName System.Windows.Forms
4443

45-
46-
# Define the user32.dll functions
4744
Add-Type @"
4845
using System;
4946
using System.Runtime.InteropServices;

0 commit comments

Comments
 (0)