scripts/print
#!/usr/bin/env bash
#
# print - Print files with sensible defaults (double-sided, b&w)
#
# Usage:
# print <file> [options]
#
# Options:
# -d, --printer <name> Printer name (default: system default)
# -n, --copies <count> Number of copies (default: 1)
# -P, --pages <range> Page range (e.g., 1-5 or 1,3,7)
# --single-sided Print single-sided (override duplex default)
# --color Print in color (override b&w default)
# --landscape Print in landscape orientation
# --fit Fit to page
# -l, --list List available printers
# -h, --help Show this help
set -euo pipefail
# Defaults
DUPLEX="two-sided-long-edge"
COLOR_MODEL="Gray"
PRINTER=""
COPIES=""
PAGES=""
LANDSCAPE=""
FIT=""
usage() {
cat <<EOF
Usage: print <file> [options]
Print files with sensible defaults (double-sided, black & white).
Options:
-d, --printer <name> Printer name (default: system default)
-n, --copies <count> Number of copies (default: 1)
-P, --pages <range> Page range (e.g., 1-5 or 1,3,7)
--single-sided Print single-sided (override duplex default)
--color Print in color (override b&w default)
--landscape Print in landscape orientation
--fit Fit to page
-l, --list List available printers
-h, --help Show this help
Examples:
print document.pdf # Double-sided, b&w, default printer
print document.pdf -d HP_LaserJet # Specific printer
print document.pdf -n 3 # 3 copies
print document.pdf --single-sided # Single-sided
print document.pdf --color # Color output
print document.pdf -P 1-5 # Pages 1-5 only
EOF
}
list_printers() {
echo "Available printers:"
echo
lpstat -p -d 2>/dev/null || echo "No printers found. Is CUPS running?"
}
# Parse arguments
FILE=""
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
usage
exit 0
;;
-l|--list)
list_printers
exit 0
;;
-d|--printer)
PRINTER="$2"
shift 2
;;
-n|--copies)
COPIES="$2"
shift 2
;;
-P|--pages)
PAGES="$2"
shift 2
;;
--single-sided)
DUPLEX="one-sided"
shift
;;
--color)
COLOR_MODEL="Color"
shift
;;
--landscape)
LANDSCAPE="yes"
shift
;;
--fit)
FIT="yes"
shift
;;
-*)
echo "Unknown option: $1" >&2
usage
exit 1
;;
*)
if [[ -z "$FILE" ]]; then
FILE="$1"
else
echo "Error: Multiple files not supported. Got: $FILE and $1" >&2
exit 1
fi
shift
;;
esac
done
# Validate file
if [[ -z "$FILE" ]]; then
echo "Error: No file specified" >&2
usage
exit 1
fi
if [[ ! -f "$FILE" ]]; then
echo "Error: File not found: $FILE" >&2
exit 1
fi
# Build lp command
LP_OPTS=()
LP_OPTS+=("-o" "sides=$DUPLEX")
LP_OPTS+=("-o" "ColorModel=$COLOR_MODEL")
[[ -n "$PRINTER" ]] && LP_OPTS+=("-d" "$PRINTER")
[[ -n "$COPIES" ]] && LP_OPTS+=("-n" "$COPIES")
[[ -n "$PAGES" ]] && LP_OPTS+=("-P" "$PAGES")
[[ -n "$LANDSCAPE" ]] && LP_OPTS+=("-o" "landscape")
[[ -n "$FIT" ]] && LP_OPTS+=("-o" "fit-to-page")
# Print
echo "Printing: $FILE"
echo "Options: ${LP_OPTS[*]}"
lp "${LP_OPTS[@]}" "$FILE"
SKILL.md
---
name: print
description: "Print files on Mac or Linux via `lp` — defaults to double-sided B&W. Supports PDF, markdown (via md-to-pdf), copies, page ranges, color, printer selection."
---
# Print
Print files on Mac or Linux using the `lp` command with sensible defaults.
## Printing Markdown
To print a markdown file, first convert it to PDF using the `/md-to-pdf` skill:
```bash
~/.claude/skills/md-to-pdf/scripts/md-to-pdf.cjs doc.md
~/.claude/skills/print/scripts/print doc.pdf
rm doc.pdf # Delete if PDF was just for printing
```
The `/md-to-pdf` skill handles Mermaid diagrams, syntax highlighting, and page numbers.
## Defaults
| Setting | Default | Rationale |
|---------|---------|-----------|
| **Duplex** | Double-sided (long-edge) | Save paper |
| **Color** | Black & white | Save toner on color printers |
These defaults can be overridden per-request.
## Usage
### Quick Print (uses system default printer)
```bash
# Print a file with defaults (double-sided, b&w)
lp -o sides=two-sided-long-edge -o ColorModel=Gray <file>
# Or use the helper script
~/.claude/skills/print/scripts/print <file>
```
### Common Options
| Option | Flag | Example |
|--------|------|---------|
| Printer | `-d <name>` | `-d HP_LaserJet_4001` |
| Copies | `-n <count>` | `-n 3` |
| Pages | `-P <range>` | `-P 1-5` or `-P 1,3,7` |
| Single-sided | `-o sides=one-sided` | Override duplex |
| Color | `-o ColorModel=Color` | Override b&w |
| Landscape | `-o landscape` | Rotate 90° |
| Fit to page | `-o fit-to-page` | Scale to fit |
### List Available Printers
```bash
lpstat -p -d
```
Shows all printers and the system default (marked with `system default destination:`).
### Check Print Queue
```bash
lpstat -o # Show pending jobs
lpstat -W completed # Show completed jobs
```
### Cancel a Job
```bash
cancel <job-id> # e.g., cancel HP_LaserJet_4001-852
cancel -a # Cancel all jobs
```
## Helper Script
The `print` script at `~/.claude/skills/print/scripts/print` wraps `lp` with the defaults:
```bash
# Basic usage
print document.pdf
# Specify printer
print document.pdf -d Brother_HL_L3280CDW_series
# Multiple copies
print document.pdf -n 3
# Single-sided color
print document.pdf --single-sided --color
# Page range
print document.pdf -P 1-5
```
Run `print --help` for all options.
## Printer-Specific Notes
### HP LaserJet 4001
- Supports duplex
- Monochrome only (no color option needed)
- Steve's default printer
### Brother HL-L3280CDW
- Color laser
- Supports duplex
- Use `--color` to override b&w default
### Brother DCP-L2550DW
- Monochrome
- Supports duplex
## Troubleshooting
### "No such file or directory"
The printer name has changed. Run `lpstat -p` to see current names.
### Job stuck in queue
```bash
lpstat -o # Check status
cancel <job-id> # Cancel stuck job
cupsenable <printer-name> # Re-enable if disabled
```
### Duplex not working
Not all printers support duplex. Check printer capabilities:
```bash
lpoptions -p <printer-name> -l | grep -i sides
```