<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dammit Jim! &#187; pygmentize</title>
	<atom:link href="http://scott.sherrillmix.com/blog/tag/pygmentize/feed/" rel="self" type="application/rss+xml" />
	<link>http://scott.sherrillmix.com/blog</link>
	<description>I'm a biologist not a...</description>
	<lastBuildDate>Tue, 12 Jan 2010 05:09:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Syntax highlighting in terminal</title>
		<link>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/</link>
		<comments>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:53:09 +0000</pubDate>
		<dc:creator>ScottS-M</dc:creator>
				<category><![CDATA[Bash/UNIX]]></category>
		<category><![CDATA[Programmer]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[pygmentize]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://scott.sherrillmix.com/blog/?p=526</guid>
		<description><![CDATA[
I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using head or grep without having to open an editor. Luckily, I remembered Pygemtize was pretty handy when syntax highlighting in LaTeX so I wondered if they had [...]]]></description>
			<content:encoded><![CDATA[<img src="/res/images/ccat.png" alt="Syntax highlighted cat" class="right"/>
<p>I was just quickly flipping through code on a terminal and got to thinking that it would be pretty handy to be able to syntax highlight when using <code>head</code> or <code>grep</code> without having to open an editor. Luckily, I remembered <a href="http://pygments.org/">Pygemtize</a> was pretty handy when <a href="http://scott.sherrillmix.com/blog/programmer/displaying-code-in-latex/">syntax highlighting in LaTeX</a> so I wondered if they had an equivalent output for terminal. It turns out they do (in standard or 256 color no less) so in a couple minutes I had a really short script for highlighting code at the terminal saved it to <code>bin/ccat</code> and was ready to go. Pygmentize really is impressive. Here's the script if anyone else is looking to do the same:</p>
<div class="syntax_hilite"><span class="langName">BASH:</span><br /><div id="bash-2">
<div class="bash"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/bin/bash#!/bin/bash</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#91;</span> ! -t <span style="color: #cc66cc;color:#800000;">0</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>/dev/stdin</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">elif</span> <span style="color: #66cc66;">&#91;</span> -f $<span style="color: #cc66cc;color:#800000;">1</span> <span style="color: #66cc66;">&#93;</span>;then</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">file=</span>$<span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">else</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"Usage: $0 code.c"</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">echo</span> <span style="color: #ff0000;">"or e.g. head code.c|$0"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">exit</span> <span style="color: #cc66cc;color:#800000;">1</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">fi</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">pygmentize -f terminal -g <span style="color: #0000ff;">$file</span> </div></li></ol></div>
</div></div><br />
<p>It just looks for stdin and if it doesn't find it it looks for a file name or takes direct input. Obviously it requires Pygmentize (which is really <a href="http://pygments.org/download/">easy to install</a> if you already have Python).</p>]]></content:encoded>
			<wfw:commentRss>http://scott.sherrillmix.com/blog/programmer/syntax-highlighting-in-terminal/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
