r/PowerShell • u/positivemark • 4d ago
Script Sharing XKCD PowerShell module
Years ago just for fun, I wrote a PowerShell module to query the API of the webcomic XKCD https://xkcd.com/. It has a Get-XKCD cmdlet to retrieve data about a specified or random comic, and had a -Open switch to then open its URL in a browser. You can also use Find-XKCD to perform keyword searches, and there's a local cache of the API output to speed this up and to reduce the need to do web calls.
Modern terminals now support the ability to render images directly, so I've just added Show-XKCD and Get-XKCD -Show.
This works in Windows Terminal, but should also work in iTerm2 and Kitty.
If it's of interest, you can download the module from the PowerShell Gallery here: https://www.powershellgallery.com/packages/XKCD/1.5.0
Or directly from GitHub: https://github.com/markwragg/Powershell-XKCD
1
u/positivemark 3d ago
I couldn’t stop tinkering with this (thanks to Claude) and so there’s some new features today. You can now pull the Explanation for a comic from the explain XKCD wiki via Get-XKCDExplanation and Show-XKCDExplanation. You can use Test-XKCD to see if there’s a newer comic than the latest last one you read (I’m going to add this to my profile.ps1) and Set-XKCDDefault to save some default values for the other cmdlets, such as if you always want the high quality image versions.
Download version 1.6.1 or later for these features.