Skip to content

Instantly share code, notes, and snippets.

@ma6174
Created September 5, 2015 14:15
Show Gist options
  • Save ma6174/1235d148902629a60f72 to your computer and use it in GitHub Desktop.
Save ma6174/1235d148902629a60f72 to your computer and use it in GitHub Desktop.
run a command and copy result to clipboard, or copy data from stdin.
#!/bin/bash
if [ $# -gt 0 ]; then
(echo "$ "$@ && exec $@) | tee /dev/fd/2 | pbcopy
else
tee /dev/fd/2 | perl -pe 'chomp if eof' | pbcopy
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment