Skip to content

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

Open
iamsharduld wants to merge 1 commit intotrack/2from
feat/copybutton-strip-prompts
Open

feat: strip "$ " shell prompts from copy button#335
iamsharduld wants to merge 1 commit intotrack/2from
feat/copybutton-strip-prompts

Conversation

@iamsharduld
Copy link
Copy Markdown

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 review from MichaelThamm and mmkay May 8, 2026 12:41
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.

1 participant