Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save david-risney/af03e49e123351c9cbad4bd2ccade63f to your computer and use it in GitHub Desktop.
Save david-risney/af03e49e123351c9cbad4bd2ccade63f to your computer and use it in GitHub Desktop.
Toast from PowerShell when long running command line finishes
copy function:prompt function:poshPrompt;
function prompt {
try {
poshPrompt;
} catch {
Write-Host ("POSH Prompt Error: " + $_);
}
try {
$lastCommandFailed = ($LastExitCode -ne $null -and $LastExitCode -ne 0) -or !$?;
$lastCommnadTookALongTime = $false;
$lastCommandTime = 0;
$h = (Get-History);
if ($h.length -gt 0) {
$lh = $h[$h.length - 1];
$lastCommandTime = $lh.EndExecutionTime - $lh.StartExecutionTime;
$lastCommandTookALongTime = $lastCommandTime.TotalSeconds -gt 10;
if ($lh.ExecutionStatus -eq "Completed" -and $lastCommandTookALongTime) {
$status = "Success: ";
if ($lastCommandFailed) {
$status = "Failed: ";
}
New-BurntToastNotification -Text $status,($lh.CommandLine);
}
}
} catch {
Write-Host ("CDHistory Prompt Error: " + $_);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment