Skip to content

Instantly share code, notes, and snippets.

@avdi
Created February 16, 2014 19:00
Show Gist options
  • Save avdi/9038972 to your computer and use it in GitHub Desktop.
Save avdi/9038972 to your computer and use it in GitHub Desktop.
Get syntax highlighted source code for pasting into e.g. Google Docs on Linux
# You will need the pygments and xclip packages
# This example highlights some Bash source code
# '-O noclasses=true' tells pygments to embed colors inline in the source
# the '-t text/html' option tells xclip what "target" to specify for the selection
pygmentize -l bash -f html -O noclasses=true mysource.sh | xclip -selection clipboard -t text/html
@jfelchner
Copy link

FWIW this is what it looks like on OSX. Note, my version highlights whatever is on the clipboard. So running:

clipsyn bash

Would take whatever is on the clipboard, syntax highlight it as a bash script and then copy it back to the clipboard.

function clipsyn {
  local syntax_type="$1"

  pbpaste | pygmentize -l $syntax_type -f rtf | pbcopy -Prefer rtf
}

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