Skip to content

Instantly share code, notes, and snippets.

@andyfriesen
Last active August 29, 2015 14:09
Show Gist options
  • Save andyfriesen/870e3489c144a5449cbe to your computer and use it in GitHub Desktop.
Save andyfriesen/870e3489c144a5449cbe to your computer and use it in GitHub Desktop.
Use Pygments to colourize code in the clipboard
#!/bin/bash
set -ex
if [ `uname` == 'Linux' ]; then
PASTE=xclip\ -o
OPEN=xdg-open
else
# Assume OSX
PASTE=pbpaste
OPEN=open
fi
echo "<style>" > colourized.html
pygmentize -S colorful -f html -a .highlight >> colourized.html
echo "</style>" >> colourized.html
echo "<body>" >> colourized.html
$PASTE | pygmentize -f html -l $1 >> colourized.html
echo "</body>" >> colourized.html
$OPEN colourized.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment