Last active
June 11, 2023 21:38
-
-
Save adam-zethraeus/52ed1da4053a01ca28ae58304a343a75 to your computer and use it in GitHub Desktop.
clip — mac clipboard pbcopy/pbpaste wrapper
This file contains 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 | |
if [ -t 0 ]; then # if no stdin to clip... | |
if [ -z "$*" ]; then # if no args to clip, paste | |
# paste | |
pbpaste | |
else # if there are args, execute as command and copy output | |
eval "${*}" | pbcopy | |
fi | |
else # if there's stdin input, copy | |
TMP=/tmp/`uuidgen` | |
exec 6<> "$TMP" | |
cat "$TMP" | pbcopy & | |
while IFS= read -r line ; do | |
echo "$line" >&6 | |
done | |
wait | |
exec 6>&- | |
rm "$TMP" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment