Toast from PowerShell when long running command line finishes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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