Skip to content

Instantly share code, notes, and snippets.

@ccsalvesen
Created March 12, 2015 08:58
Show Gist options
  • Save ccsalvesen/5beeed76e6907cbaba52 to your computer and use it in GitHub Desktop.
Save ccsalvesen/5beeed76e6907cbaba52 to your computer and use it in GitHub Desktop.
copy files and directories to clipboard. paste in a terminal window.
#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "${0} - copy selfextracting archive of files to clipboard."
echo ""
echo "Syntax: $0 <file(s)>"
exit 1
fi
TEMPFILE=$(mktemp)
out=$(which xclip 2>/dev/null || echo '/bin/cat')
(
echo -n 'echo "'
tar -c -j --exclude-vcs -f - ${@} | base64 -w0 #$(tput cols)
echo '"| base64 -d - | tar xjvf -'
) | tee ${TEMPFILE} | ${out} && \
echo "Copied self extracting archive of ${@} to clipboard. ($(du -h ${TEMPFILE}|cut -f1))" && \
rm -f ${TEMPFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment