Skip to content

Instantly share code, notes, and snippets.

@adam-zethraeus
Last active June 11, 2023 21:38
Show Gist options
  • Save adam-zethraeus/52ed1da4053a01ca28ae58304a343a75 to your computer and use it in GitHub Desktop.
Save adam-zethraeus/52ed1da4053a01ca28ae58304a343a75 to your computer and use it in GitHub Desktop.
clip — mac clipboard pbcopy/pbpaste wrapper
#!/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