Created
September 19, 2022 16:21
-
-
Save jeremysimmons/bdee1d8163667ea2d37d28058b295d0e to your computer and use it in GitHub Desktop.
dotnet format with desktop notify script
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
fcs() { | |
OUTPUT=$(dotnet format) | |
if [ $? -eq 0 ]; then | |
powershell -file $HOME/Toast.ps1 "Dotnet Format", "Completed successfully" | |
else | |
powershell -file $HOME/Toast.ps1 "Dotnet Format", "Failed $OUTPUT" | |
fi | |
} |
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
# https://den.dev/blog/powershell-windows-notification/ | |
function Show-Notification { | |
[cmdletbinding()] | |
Param ( | |
[string] | |
$ToastTitle, | |
[string] | |
[parameter(ValueFromPipeline)] | |
$ToastText | |
) | |
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null | |
$Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) | |
$RawXml = [xml] $Template.GetXml() | |
($RawXml.toast.visual.binding.text|where {$_.id -eq "1"}).AppendChild($RawXml.CreateTextNode($ToastTitle)) > $null | |
($RawXml.toast.visual.binding.text|where {$_.id -eq "2"}).AppendChild($RawXml.CreateTextNode($ToastText)) > $null | |
$SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument | |
$SerializedXml.LoadXml($RawXml.OuterXml) | |
$Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml) | |
$Toast.Tag = "PowerShell" | |
$Toast.Group = "PowerShell" | |
$Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1) | |
$Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell") | |
$Notifier.Show($Toast); | |
} | |
if($args.Count -lt 2) { | |
Write-Output "Requires 2 arguments" | |
Write-Output $args.Count | |
Exit 1 | |
} | |
Show-Notification -ToastTitle $args[0] -ToastText $args[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment