Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active April 29, 2021 19:56
Show Gist options
  • Save Jaykul/3fe51b26ef279eb0d5a5939850b89dea to your computer and use it in GitHub Desktop.
Save Jaykul/3fe51b26ef279eb0d5a5939850b89dea to your computer and use it in GitHub Desktop.
Weather Everywhere
$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] }
@Jaykul
Copy link
Author

Jaykul commented Apr 14, 2020

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment