Skip to content

Instantly share code, notes, and snippets.

@dekokun
Created February 27, 2012 10:09
Show Gist options
  • Save dekokun/1922934 to your computer and use it in GitHub Desktop.
Save dekokun/1922934 to your computer and use it in GitHub Desktop.
for Mac, Copy File to clipboard or Copy standard input to clipboard .
#!/bin/bash
COMMAND=`basename $0`
usage(){
echo "Usage: $COMMAND FILE"
echo "With no FILE, read standard input."
}
error(){
local ERROR_MESSAGE=$@
echo "$COMMAND: $ERROR_MESSAGE"
echo
usage
exit 1
}
while getopts h flag
do
case $flag in
h) usage;exit 1;;
esac
done
if [ ! -z $1 ]; then
if [ -d $1 ];then
error "$1: It is Directory"
elif [ -e $1 ]; then
cat $1 | pbcopy
else
error "$1: No such file"
fi
elif [ -p /dev/stdin ]; then
pbcopy
else
error "No file and standard input"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment