Piping anything into the macOS clipboard
pbcopy reads from stdin and stuffs whatever it gets into the system
clipboard. pbpaste does the reverse. Together they’re the cheapest
“copy from terminal” workflow on macOS.
# Copy the contents of a file
pbcopy < notes.txt
# Copy a command's output
git rev-parse HEAD | pbcopy
# Round-trip through a tool, then put it back on the clipboard
pbpaste | jq . | pbcopy
The last one is the trick I use most often: paste some messy JSON from a
chat thread, run it through jq, and have a tidy version waiting on the
clipboard for me to paste back.