Last active
August 15, 2023 08:02
-
-
Save devblackops/2dea8440b48b4d378f220841c07ec2a2 to your computer and use it in GitHub Desktop.
Display highly visible notification if the last command failed in the Microsoft Terminal using PowerShell
This file contains hidden or 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
# Put this code in your PowerShell profile script | |
# This requires the MSTerminalSettings module which you can download with: | |
# Install-Module MSTerminalSettings -Scope CurrentUser -Repository PSGallery | |
Import-Module MSTerminalSettings | |
$msTermProfileName = 'pwsh' # Replace with whatever Terminal profile name you're using | |
$msTermProfile = Get-MSTerminalProfile -Name $msTermProfileName | |
$script:bombThrown = $false | |
function prompt { | |
if ($? -eq $false) { | |
# RED ALERT!!! | |
# Only do this if we're using Microsoft Terminal | |
if ((Get-Process -Id $PID).Parent.Parent.ProcessName -eq 'WindowsTerminal') { | |
Set-MSTerminalProfile -Name $msTermProfile.name -BackgroundImage 'https://media.giphy.com/media/HhTXt43pk1I1W/giphy.gif' -UseAcrylic:$false | |
$script:bombThrown = $true | |
} | |
} else { | |
# Reset to previous settings | |
if ($script:bombThrown) { | |
Set-MSTerminalProfile -Name $msTermProfile.name -BackgroundImage $msTermProfile.backgroundImage -UseAcrylic:$msTermProfile.useAcrylic | |
$script:bombThrown = $false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might consider adding a blowoff valve for
robocopy
:The return code from Robocopy is a bitmap, defined as follows: