Created
October 11, 2025 20:55
-
-
Save icylace/8f24e034711d5cd0e2f30805e814542a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Pipes in/out of the macOS clipboard. | |
| # | |
| # Usage: <command> | cb # Copy stdin. | |
| # cb <file> # Copy a file's contents. | |
| # cb | <command> # Pipe clipboard's content into a command. | |
| # cb > <file> # Paste into a file. | |
| # | |
| # Based on: | |
| # https://stackoverflow.com/a/19458217 | |
| # https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/clipboard.zsh | |
| # | |
| cb() { | |
| if [ -p /dev/stdin ] ; then | |
| # Copy from stdin. | |
| pbcopy | |
| return | |
| fi | |
| if [ -z "$1" ] ; then | |
| # Paste to stdout. | |
| pbpaste | |
| return | |
| fi | |
| if [ -f "$1" ] ; then | |
| # Copy a file's contents. | |
| pbcopy < "$1" | |
| return | |
| fi | |
| local red='\e[0;31m' | |
| local reset='\e[0m' | |
| echo "${red}ERROR: $1 is not a file and there's nothing piped in from stdin.${reset}" | |
| return 1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment