spec-copy-selection
v1.0.16
Published
A CLI utility for copying text to clipboard
Readme
spec-copy-selection
A CLI tool to copy specific line ranges from files to your clipboard. Designed for developers who need to quickly extract and share code snippets with proper context.
Installation
Run directly via npx (no installation required):
npx spec-copy-selection@latest <file-path>:<start-line>-<end-line>Basic Usage
Copy lines from any file to your clipboard:
# Copy lines 1-5 from package.json
spec-copy-selection ./package.json:1-5
# Copy lines 10-20 from a TypeScript file
spec-copy-selection src/index.ts:10-20
# Windows absolute paths are supported
spec-copy-selection D:\projects\file.ts:10-20Output format for standard files:
src/index.ts:10-20
[selected content]Backlog.md Special Features
When copying from specs/[feature]/backlog.md files, the tool provides special formatting to help with spec-driven workflows.
Special Output Format
Copying from a backlog file produces formatted output with context:
spec-copy-selection specs/cli-file-operations/backlog.md:69-70Output:
spec: cli-file-operations
[selected content]
(note: this request was extracted from specs/cli-file-operations/backlog.md:69-70)Automatic Separator Insertion
When copying a non-first section from a backlog.md file:
- The system automatically inserts a
---separator before the selected content in the source file - Line numbers are adjusted (+3) after insertion to account for the added separator
- This helps maintain clean section boundaries in backlog files
Note: Separators are only inserted when:
- The file already contains at least one
---separator - There is content after the last separator (indicating a new section has started)
- You're not copying from line 1
IDE Integration (JetBrains External Tools)
Configure as an external tool with these variables:
bunx
spec-copy-selection $FilePathRelativeToProjectRoot$:$SelectionStartLine$-$SelectionEndLine$
$ContentRoot$

Error Handling
The tool provides clear error messages for common issues:
- Invalid format:
Invalid format. Usage: spec-copy-selection <file-path>:<start-line>-<end-line> - File not found:
File not found: {file-path} - Invalid range:
Invalid range: start line ({start}) cannot be greater than end line ({end})
Run spec-copy-selection --help for usage instructions.
