Last active
April 29, 2021 19:56
-
-
Save Jaykul/3fe51b26ef279eb0d5a5939850b89dea to your computer and use it in GitHub Desktop.
Weather Everywhere
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
$global:WeatherJob = Start-ThreadJob { | |
while($true) { | |
(irm "wttr.in?format=3").Trim() -replace "^.*:\s*"; sleep 300 | |
} | |
} -Name WeatherQuery | |
$null = Register-ObjectEvent -InputObject $WeatherJob.Output -EventName DataAdded -Action { | |
# The $Sender is the actual Output collection | |
# $EventArgs includes the index at which the output was added | |
# Update the Window Title with the weather each time it updates | |
$Host.Ui.RawUi.WindowTitle = "PS " + $PSVersionTable.PSVersion + " " + $Sender[$EventArgs.Index] | |
# Clean out old Output (so there's only ever one) | |
for ($i=$EventArgs.Index -1; $i -gt 0; $i--) { | |
$Sender.RemoveAt($i) | |
} | |
} -SourceId WeatherUpdate | |
# for bonus points, use the output in your prompt: | |
Add-PowerLineBlock { $WeatherJob.Output[-1] } |
Author
Jaykul
commented
Apr 14, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment