Skip to content

feat: strip "$ " shell prompts from copy button#341

Merged
iamsharduld merged 1 commit into
mainfrom
feat/copybutton-strip-prompts-main
May 12, 2026
Merged

feat: strip "$ " shell prompts from copy button#341
iamsharduld merged 1 commit into
mainfrom
feat/copybutton-strip-prompts-main

Conversation

@iamsharduld
Copy link
Copy Markdown
Contributor

Issue

Copying a $ command block from our docs pastes the $ along with it, which then fails when run in a real shell. Affects every shell code block across the site.

Solution

Adds two lines to docs/conf.py configuring sphinx-copybutton to strip the $ prompt on copy. Also sets copybutton_line_continuation_character = "\\" so multi-line commands joined by \ copy as a single command.

Checklist

Context

sphinx-copybutton (auto-enabled by canonical_sphinx) supports prompt-stripping but doesn't apply it by default. With copybutton_prompt_text = r"\$ " and copybutton_prompt_is_regexp = True, blocks containing $ -prefixed lines copy only the command portion, and blocks without prompts (e.g. JSON output) copy verbatim.

Aligns with the [Canonical Documentation Style Guide](https://docs.ubuntu.com/styleguide/en/), which advises against prompt marks in code samples for this exact reason.

Testing Instructions

  1. cd docs && make clean && make serve
  2. Open any tutorial page, find a $ shell block, click the copy button.
  3. Paste somewhere — should yield command not $ command.
  4. Verify a JSON or output-only block still copies verbatim.

Upgrade Notes

None — additive config-only change. No content or build-pipeline changes.

@iamsharduld iamsharduld requested a review from mmkay May 12, 2026 08:21
@iamsharduld iamsharduld requested a review from a team as a code owner May 12, 2026 08:21
Copy link
Copy Markdown
Contributor

@mmkay mmkay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@iamsharduld iamsharduld force-pushed the feat/copybutton-strip-prompts-main branch from 1fc2312 to b2d62fe Compare May 12, 2026 09:22
@iamsharduld iamsharduld merged commit 988cb92 into main May 12, 2026
5 checks passed
@iamsharduld iamsharduld deleted the feat/copybutton-strip-prompts-main branch May 12, 2026 09:39
@MichaelThamm
Copy link
Copy Markdown
Contributor

MichaelThamm commented May 12, 2026

FYI this is a comment from Yanisa, who was our temp technical author

Removing it from copy is helpful if prompts are there. IMO I don't like them mostly because the main argument for having them is to denote what is the input vs what is the output, but this encourages poor practices of just copying large sections of the terminal w/o sufficient explanation anyway

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants