Help and docs
Sign in

grindlemire/dotfiles code browser

main 0375daa
markdown · 79 lines · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
name: clip
version: 1.2.0
description: |
  Copy text to the macOS clipboard via stdin so paragraph breaks and literal
  newlines survive (no terminal line-wrap mangling, no temp files). Triggered
  by the /clip slash command or when the user says "copy to clipboard", "copy
  this to my clipboard", "put that on the clipboard", "pbcopy this", or
  otherwise asks to get a chunk of conversation text onto their clipboard for
  manual editing or pasting elsewhere.
allowed-tools:
  - Bash
---

# clip

## When to use

Trigger when the user runs `/clip` or asks to copy text to their clipboard.
Common phrasings:

- "/clip"
- "copy to clipboard"
- "copy this to my clipboard"
- "put it on the clipboard"
- "pbcopy this"

## What text to copy

Unless the user specifies otherwise, copy the most recently proposed chunk of
text from the assistant (e.g., a draft message, a code snippet, a response
they're about to send). If `/clip <text>` is invoked with explicit text after
it, copy that text. If ambiguous, ask which block.

## Procedure

Pipe the text directly to `pbcopy` via a quoted heredoc in a single `Bash`
call. No temp file, no cleanup step. The single-quoted `'CLIPEOF'` delimiter
prevents shell expansion of backticks, `$`, etc. inside the content.

Run this with `dangerouslyDisableSandbox: true`. The command sandbox blocks the
clipboard syscall **silently**: `pbcopy` is prevented from writing but still
exits 0, so a blind `echo "Copied"` reports false success. Disable the sandbox
and verify with `pbpaste` instead of trusting the exit code:

```
pbcopy <<'CLIPEOF'
<exact text to copy, preserving paragraph breaks>
CLIPEOF
echo "--- exit: $? ---"; pbpaste | head -1
```

Confirm the `pbpaste` output matches the start of what you copied, then tell the
user in one short line that the text is on the clipboard.

## Platform fallbacks

The heredoc-to-stdin pattern is identical on every platform; only the command
changes:

- **macOS (default):** `pbcopy`
- **Linux Wayland:** `wl-copy`
- **Linux X11:** `xclip -selection clipboard` or `xsel --clipboard --input`
- **Windows (WSL / Git Bash):** `clip.exe`

Detect via `uname` if the platform is unclear.

## Notes

- Always run the copy with `dangerouslyDisableSandbox: true`. The sandbox blocks
  the clipboard write silently (no error, exit 0), so without this the copy
  appears to succeed but nothing lands on the clipboard. The user can allow
  clipboard writes via `/sandbox` to avoid the per-command override.
- If the content contains the literal string `CLIPEOF`, switch to a different
  unique delimiter (e.g. `CLIPEOF_2`).
- Never echo the full text back to the user as part of confirmation; they
  already have it in the conversation. Just confirm the copy succeeded.
- Do not write the text to a file as an intermediate step. The whole point of
  this skill is to keep the copy atomic and side-effect-free.