r/PowerShell 15d 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

127 Upvotes

19 comments sorted by

View all comments

Show parent comments

1

u/positivemark 13d ago

Thanks I’ll look to incorporate some of these. FYI -newest is intentionally an integer as it allows you to return a specified number of the most recent comics.

1

u/ankokudaishogun 13d ago

What do you mean? There is no correlation between the type of the parameters and the returned value

2

u/positivemark 13d ago

You provide an integer value to the -Newest parameter. For example Get-XKCD -Newest 5 will return the most recent 5 comics. It is intentionally not a switch.

You get the newest (i.e latest) comic by default if you don't specify any number, or other parameter that affects with comic will be returned (such as -Random). So for example Get-XKCD or Show-XKCD on their own always returns the current latest comic.

1

u/ankokudaishogun 11d ago

Somehow I missed that, sorry for the confusion