Skip to content

Instantly share code, notes, and snippets.

@brianpeiris
Created September 7, 2012 18:23
Show Gist options
  • Save brianpeiris/3668357 to your computer and use it in GitHub Desktop.
Save brianpeiris/3668357 to your computer and use it in GitHub Desktop.
Powershell script for dealing with running applications
function list-windows () {
ps | ?{$_.mainwindowtitle} | select processname, mainwindowtitle | ft -a
}
set-alias lw list-windows
function levdis ($strA, $strB) {
$n = $strA.Length;
$m = $strB.Length;
$d = @();
for ($i = 0; $i -le $n; $i++) {
$d += ,@();
for ($j = 0; $j -le $n; $j++) {
$d[$i] += -1;
}
}
if ($n -eq 0) { return $m; }
if ($m -eq 0) { return $n; }
for ($i = 0; $i -le $n; $i++) {
$d[$i][0] = $i;
}
for ($j = 0; $j -le $m; $j++) {
$d[$j][0] = $j
}
for ($i = 1; $i -le $n; $i++)
{
for ($j = 1; $j -le $m; $j++)
{
if ($strB[$j - 1] -eq $strA[$i - 1]) { $cost = 0; }
else { $cost = 1; }
$d[$i][$j] = [math]::Min(
[math]::Min($d[$i - 1][$j] + 1, $d[$i][$j - 1] + 1),
$d[$i - 1][$j - 1] + $cost
);
}
}
return $d[$n][$m];
}
function focus-window ($query) {
$windows = ps | ?{$_.mainwindowtitle}
$windows | select mainwindowtitle, @{n='dis';e={levdis $_.mainwindowtitle $query}} | sort dis
}
set-alias fo focus-window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment