syntax highlighting in the terminal with pygments
the Pygments syntax highlighting library comes with a CLI tool 'pygmentize', which has a formatter for terminal color codes:
pygmentize -f terminal hello.coffee
you can pipe it into less to paginate output:
pygmentize -f terminal hello.coffee | less -R
and then set an alias for dead-simple CLI usage (example is for zsh):
pretty() { pygmentize -f terminal "$1" | less -R }
you can also use the 'terminal256' formatter for a 256 color terminal.
Written by Tom Jakubowski
Related protips
4 Responses
That's cool, already add alias to my .zshrc :)
over 1 year ago
·
You are probably better off with the following function
pretty() { pygmentize -f terminal $* | less -R }
Gives you more freedom to pass options like
pretty -l sh .zshrc
over 1 year ago
·
Why not adding -g
to allow auto detection of lexer ;-) ?
over 1 year ago
·
pless() { less -f terminal256 -g -P style=monokai $* | less -FiXRM }
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Console
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#