Skip to content

Show XKCD

AzureDevOps edited this page Oct 6, 2026 · 8 revisions

Show-XKCD

SYNOPSIS

Displays a comic's title, image, and alt text in the console.

SYNTAX

Specific (Default)

Show-XKCD [[-Number] <Int32[]>] [-HighQuality] [-StatePath <String>] [-Offline] [-CachePath <String>]
 [-DownloadPath <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

Next

Show-XKCD [-Next] [-HighQuality] [-StatePath <String>] [-Offline] [-CachePath <String>]
 [-DownloadPath <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

Previous

Show-XKCD [-Previous] [-HighQuality] [-StatePath <String>] [-Offline] [-CachePath <String>]
 [-DownloadPath <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

File

Show-XKCD [-Path] <String[]> [-HighQuality] [-StatePath <String>] [-Offline] [-CachePath <String>]
 [-DownloadPath <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

The Show-XKCD cmdlet gets and displays a comic in the console: the title above, the image (if your terminal supports the Sixel, Kitty, or iTerm2 inline image graphics protocol), and the alt text below.

By default, Show-XKCD displays the latest available comic. When you use the -Number parameter (aliased as -Num) you can specify one or more specific comics to display.

Each displayed comic updates a local state file with two records: the highest-numbered comic you've ever viewed, used by Test-XKCD to report how many new comics have been published since you last checked; and the comic you most recently displayed in either direction, used by -Next and -Previous so you can page back and forth through comics sequentially. -Next displays nothing once you've reached the latest comic, and -Previous displays nothing once you've reached comic #1.

Use -Path to display a comic from a file previously saved with Export-XKCDTerminalImage instead of fetching it from the xkcd API -- useful for redisplaying a comic without needing network access, or for a comic whose image was rendered on another machine. The saved image is written to the console as-is rather than being re-rendered, so it's only guaranteed to display correctly in a terminal that supports the same graphics protocol it was exported with; a warning is shown if that doesn't match the protocol detected for the terminal you're displaying it in.

Use -Offline to display a comic using data from the local cache (created/refreshed by Update-XKCDCache) and an image previously saved with Get-XKCD -Download, instead of fetching either from the xkcd API -- this also governs where -Next/-Previous and the default (no -Number) consider the "latest" comic to be. If the comic's image hasn't been downloaded to -DownloadPath yet, a warning is shown asking you to use -Download first, and that comic is skipped. Defaults to the value saved with Set-XKCDDefault -Offline, if any.

EXAMPLES

EXAMPLE 1

Show-XKCD

Displays the latest comic.

EXAMPLE 2

Show-XKCD 2000

Displays comic number 2000.

EXAMPLE 3

Get-XKCD -Random | Show-XKCD

Gets a random comic and displays it in the console.

EXAMPLE 4

Find-XKCD -Query 'Spider' | Get-XKCD | Show-XKCD

Finds comics with 'Spider' in the title and displays each one in the console.

EXAMPLE 5

Get-XKCD -Show

Shorthand equivalent of: Get-XKCD | Show-XKCD

EXAMPLE 6

Show-XKCD -Next

Displays the comic after the one you most recently displayed with Show-XKCD or Get-XKCD -Show, as recorded in the state file. Displays nothing if you're already at the latest comic.

EXAMPLE 7

Show-XKCD -Previous

Displays the comic before the one you most recently displayed with Show-XKCD or Get-XKCD -Show, as recorded in the state file. Calling -Previous repeatedly steps back further each time. Displays nothing if you're already at comic #1.

EXAMPLE 8

Show-XKCD -Path .\353.xkcdterm.json

Displays the comic saved to '.\353.xkcdterm.json' by Export-XKCDTerminalImage, without fetching anything from the xkcd API.

EXAMPLE 9

Export-XKCDTerminalImage -Number 353 -PassThru | Show-XKCD

Exports comic number 353 and immediately displays it from the saved file.

EXAMPLE 10

Show-XKCD -Offline

Displays the latest cached comic, rendering its image from a copy previously saved with Get-XKCD -Download, instead of fetching either from the xkcd API.

EXAMPLE 11

Show-XKCD -Num 353 -Offline -DownloadPath C:\XKCD

Displays comic number 353 from the local cache, rendering its image from a copy previously saved to C:\XKCD with Get-XKCD -Download -Path C:\XKCD. Warns and skips displaying the comic if no copy of its image is found there.

PARAMETERS

-Number

Displays the specified comics. Accepts array input. By default the latest comic is displayed.

Type: Int32[]
Parameter Sets: Specific
Aliases: Num

Required: False
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-Next

Displays the comic after the one most recently displayed with Show-XKCD or Get-XKCD -Show, as recorded in the state file. Displays nothing if you're already at the latest comic.

Type: SwitchParameter
Parameter Sets: Next
Aliases:

Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Previous

Displays the comic before the one most recently displayed with Show-XKCD or Get-XKCD -Show, as recorded in the state file. Displays nothing if you're already at comic #1.

Type: SwitchParameter
Parameter Sets: Previous
Aliases:

Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Path

Displays the comic saved in the specified file(s), previously created with Export-XKCDTerminalImage, instead of fetching it from the xkcd API. Accepts array input and FileInfo objects via the pipeline (e.g. from Get-ChildItem or Export-XKCDTerminalImage -PassThru).

Type: String[]
Parameter Sets: File
Aliases: FullName

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False

-HighQuality

Displays the higher resolution (_2x) version of the image, where available. Comics that do not have a higher resolution version are displayed at the standard quality instead. Defaults to the value saved with Set-XKCDDefault -HighQuality, if any.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'HighQuality' -Value $false)
Accept pipeline input: False
Accept wildcard characters: False

-StatePath

Path to the file used to track the number of the most recently viewed comic (used by Test-XKCD). By default this is in the user's per-user data directory (~/.xkcd), unless a default has been saved with Set-XKCDDefault -StatePath.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'StatePath' -Value (Get-XKCDUserDataPath -FileName 'XKCD.state.json' -LegacyDirectory $PSScriptRoot))
Accept pipeline input: False
Accept wildcard characters: False

-Offline

Displays comic data from the local cache, and the comic's image from a copy previously saved with Get-XKCD -Download, instead of fetching either from the xkcd API. Warns and skips the comic if its image hasn't been downloaded to -DownloadPath yet. Defaults to the value saved with Set-XKCDDefault -Offline, if any.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Offline' -Value $false)
Accept pipeline input: False
Accept wildcard characters: False

-CachePath

Use with -Offline to specify where comic data is cached. By default this is within the module path, unless a default has been saved with Set-XKCDDefault -CachePath.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'CachePath' -Value (Join-Path $PSScriptRoot 'XKCD.json'))
Accept pipeline input: False
Accept wildcard characters: False

-DownloadPath

Use with -Offline to specify the local directory to look for previously downloaded comic images in (as saved by Get-XKCD -Download). By default this is the current working directory, unless a default has been saved with Set-XKCDDefault -Path.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Path' -Value $PWD)
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{Fill ProgressAction Description}}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

NOTES

RELATED LINKS

https://github.com/markwragg/Powershell-XKCD/wiki/Show-XKCD

https://xkcd.com/json.html

Clone this wiki locally