r/PowerShell
•
u/positivemark
•
Aug 27 '26
•
1
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
10
u/positivemark Aug 27 '26
Now also supports the vscode terminal, as long as you’ve set terminal.integrated.enableImages to true. Supported as of version 1.5.3 of the module.
6
u/recoveringasshole0 Aug 27 '26
(waits for relevant XKCD link)
12
u/Breitsol_Victor Aug 27 '26
Fun and learning in one package. Noice.
11
u/AGsec Aug 27 '26
very nice, this is the kind of stuff I love to see on r/powershell.
7
u/ankokudaishogun Aug 27 '26
Take my upvote and do away!
1
u/positivemark Aug 28 '26
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.
1
u/positivemark Aug 29 '26
As of version 1.6.3 of the module you can now paginate through the comics by using
-Nextor-PreviousonGet-XKCDorShow-XKCD.It will also output a warning if a Sixel rendered image is likely to take a long time, based on its size. Some XKCD comics are big (although not too many).
I also thought that
Text-XKCDshould have the option to test the existence of a specific comic, so you can now doTest-XKCD 9999and get a true/false result.3
u/BlackV Aug 27 '26
Now this is what I call content :)
2
u/Andrew-Powershell Aug 27 '26
Love this, Mark! You should come back on the podcast soon and talk about it with me
1
u/PDQ_Brockstar Aug 27 '26
This is awesome!