Skip to content

Instantly share code, notes, and snippets.

@zachallaun
Last active December 18, 2015 19:29
Show Gist options
  • Select an option

  • Save zachallaun/5833659 to your computer and use it in GitHub Desktop.

Select an option

Save zachallaun/5833659 to your computer and use it in GitHub Desktop.
Zsh function to copy pygmentized code as RTF to clipboard. Can be pasted directly into applications like Keynote. Based on https://gist.github.com/cormacrelf/2282280.
# copy pygmentized code to clipboard as rtf
#
# $ copyrtf code.py
# $ copyrtf code.py monokai
# $ copyrtf code.py monokai 24
copyrtf() {
local STYLE
local FONTSIZE
if [[ -z $2 ]]; then
STYLE="monokai"
else
STYLE=$2
fi
if [[ -z $3 ]]; then
FONTSIZE=24
else
FONTSIZE=$3
fi
pygmentize -f rtf -O "style=$STYLE,fontface=Inconsolata" $1 |
# font size (RTF font sizes are doubled)
sed "s/\\\\f0/\\\\f0\\\\fs$(($FONTSIZE * 2))/g" |
pbcopy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment