Skip to content

Instantly share code, notes, and snippets.

@simono
Created March 5, 2014 23:58
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save simono/9379347 to your computer and use it in GitHub Desktop.
Save simono/9379347 to your computer and use it in GitHub Desktop.
#!/bin/zsh
#
# Highlight a given file and copy it as RTF.
#
# Simon Olofsson <simon@olofsson.de>
#
set -o errexit
set -o nounset
# 1. Run pygmentize
# 2. Set the fontsize to 30 Points (=60 half-points)
# 3. Remove all newlines
# 4. Remove trailing paragraph, to prevent a line break
# 5. Copy the result to the clipboard
pygmentize -f rtf -O 'fontface=Monaco,style=tango' $1 | sed 's;\\f0;\\f0\\fs60;g' | tr -d '\n' | sed 's;\\par}$;};' | pbcopy
@phdesign
Copy link

pygmentize v2.0 now supports fontsize. Also you could pass all command line arguments onto pygmentize, e.g.

pygmentize -f rtf -O 'fontface= Monaco,fontsize=60,style= tango' "$@" | tr -d '\n' | sed 's;\\par}$;};' | pbcopy
# USAGE: highlight.sh -l css styles.css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment