<?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>The efnx code blog. &#187; Shell Scripting</title>
	<atom:link href="http://efnx.com/topics/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://efnx.com</link>
	<description>code. blog.</description>
	<lastBuildDate>Wed, 18 Jan 2012 20:48:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>WordPress Auto-Update Script For A Linux Server</title>
		<link>http://efnx.com/wordpress-auto-update-script-for-a-linux-server/</link>
		<comments>http://efnx.com/wordpress-auto-update-script-for-a-linux-server/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 19:09:38 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=163</guid>
		<description><![CDATA[I wrote a little update script for my server to auto update my wordpress installation and figured it might help some other people as well. To use it you simply supply as arguments to the script three things: 1. the directory where your wordpress install lives 2. the name of the backups you&#8217;d like to [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a little update script for my server to auto update my wordpress installation and figured it might help some other people as well. To use it you simply supply as arguments to the script three things: </p>
<p>1. the directory where your wordpress install lives<br />
2. the name of the backups you&#8217;d like to create for that directory<br />
3. the version of the wordpress install you&#8217;d like to upgrade to</p>
<p>For example, on my server I use this command to update my wp version:</p>
<p>sudo ./updateWordpress.sh /path/to/wordpress/installation efnx 2.7.1<br />
[enter password]<br />
[watch output]</p>
<p>done!</p>
<p>Here is the code to my script:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #007800;">DIR2UPDATE</span>=<span style="color: #007800;">$1</span><br />
<span style="color: #007800;">NAME</span>=<span style="color: #007800;">$2</span><br />
<span style="color: #007800;">VERSION</span>=<span style="color: #007800;">$3</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Beginning update of <span style="color: #007800;">$DIR2UPDATE</span> to version <span style="color: #007800;">$VERSION</span>...&quot;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> wordpress_svn <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #007800;">day</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">&quot; &quot;</span> -f3<span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; <span style="color: #007800;">tme</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">&quot; &quot;</span> -f4<span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; <span style="color: #007800;">hour</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tme}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span><span style="color: #ff0000;">&quot;:&quot;</span> -f1<span style="color: #000000; font-weight: bold;">`</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007800;">fileday</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lh</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> wordpress_svn <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">37</span>-<span style="color: #000000;">39</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; <span style="color: #007800;">filehour</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lh</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> wordpress_svn <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">40</span>-<span style="color: #000000;">41</span><span style="color: #000000; font-weight: bold;">`</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${fileday}</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #800000;">${day}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SVN directory not up to date, [ file's date <span style="color: #007800;">${fileday}</span> != today <span style="color: #007800;">${day}</span> ] deleting and updating&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> wordpress_svn<span style="color: #000000; font-weight: bold;">/*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> wordpress_svn<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.automattic.com<span style="color: #000000; font-weight: bold;">/</span>wordpress<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VERSION}</span> .<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$filehour</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;<span style="color: #007800;">$hour</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SVN directory not up to date, [ file's hour <span style="color: #007800;">${filehour}</span> != now <span style="color: #007800;">${hour}</span> ] deleting and updating&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> wordpress_svn<span style="color: #000000; font-weight: bold;">/*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> wordpress_svn<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.automattic.com<span style="color: #000000; font-weight: bold;">/</span>wordpress<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VERSION}</span> .<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;SVN directory is up to date, skipping update&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> wordpress_svn<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating new svn directory and checking out version <span style="color: #007800;">$VERSION</span>...&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> wordpress_svn;<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> wordpress_svn;<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.automattic.com<span style="color: #000000; font-weight: bold;">/</span>wordpress<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VERSION}</span> .;<br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> wordpress_int <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Removing old intermediate container...&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> wordpress_int;<br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating new intermediate container...&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> wordpress_int<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Moving version <span style="color: #007800;">$VERSION</span> files into intermediate container...&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-rpf</span> wordpress_svn<span style="color: #000000; font-weight: bold;">/*</span> wordpress_int<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Moving config and custom files from <span style="color: #007800;">$NAME</span> into intermediate container...&quot;</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-p</span> <span style="color: #800000;">${DIR2UPDATE}</span><span style="color: #000000; font-weight: bold;">/</span>wp-config.php wordpress_int<br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-rpf</span> <span style="color: #800000;">${DIR2UPDATE}</span><span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/*</span> wordpress_int<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-p</span> <span style="color: #800000;">${DIR2UPDATE}</span><span style="color: #000000; font-weight: bold;">/</span>.htaccess wordpress_int<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Updating svn for wp-content'</span><br />
<span style="color: #c20cb9; font-weight: bold;">svn</span> update wordpress_int<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Backing up <span style="color: #007800;">$DIR2UPDATE</span>...&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #800000;">${NAME}</span>_backup<br />
<span style="color: #666666; font-style: italic;">#mv -f ${DIR2UPDATE}/* ${NAME}_backup &nbsp; # if you'd like to mv instead of cp</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-rpf</span> <span style="color: #800000;">${DIR2UPDATE}</span><span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #800000;">${NAME}</span>_backup<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-czvf</span> <span style="color: #800000;">${NAME}</span>_backup.tar.gz <span style="color: #800000;">${NAME}</span>_backup<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #800000;">${NAME}</span>_backup<br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Removing svn data from intermediate container...'</span> <br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> wordpress_int<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> .svn<span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Moving intermediate container contents to <span style="color: #007800;">$DIR2UPDATE</span>...&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-rpf</span> wordpress_int<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #800000;">${DIR2UPDATE}</span></div></div>
<p>Or you can just download the script here [rightclick + 'save as']-><br />
<a href='http://blog.efnx.com/wp-content/uploads/2009/03/updatewordpress.sh'>updateWordpress.sh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/wordpress-auto-update-script-for-a-linux-server/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Formatting gcc, g++ Output Using PHP In TextMate</title>
		<link>http://efnx.com/formatting-gcc-g-output-using-php-in-textmate/</link>
		<comments>http://efnx.com/formatting-gcc-g-output-using-php-in-textmate/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 22:55:53 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[compiler]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=70</guid>
		<description><![CDATA[While at ZendCon08 I saw a lot of people sharing the same love for TextMate as myself. I fricken love TextMate. Some of my friends laughed at me, saying &#8220;Bah, TM&#8217;s not an IDE, why do you want to write shell scripts to try to make it one?&#8221; And I&#8217;d be like, &#8220;I&#8217;m an ActionScript [...]]]></description>
			<content:encoded><![CDATA[<p>While at ZendCon08 I saw a lot of people sharing the same love for TextMate as myself. I fricken love TextMate. Some of my friends laughed at me, saying &#8220;Bah, TM&#8217;s not an IDE, why do you want to write shell scripts to try to make it one?&#8221; And I&#8217;d be like, &#8220;I&#8217;m an ActionScript developer, there&#8217;s no point in using a sledge hammer to pound in nails.&#8221; This makes sense because my friends use Eclipse. I tried Eclipse but it&#8217;s so huge and the plugins are huge and the interface is cluttered and theming syntax-coloring is a pain. So when I got home from ZendCon, with my renewed love for PHP, and my continual quest to eventually be a good C programmer, I decided to write a gcc parser script that linked back into TextMate to go directly to my errors. I use a dark syntax theme, a slightly modded Amy, and the parser reflects that. Check out a picture of these gcc errors:<br />
<div id="attachment_71" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.efnx.com/wp-content/uploads/2008/09/phpgccparse.png" rel="lightbox"><img src="http://blog.efnx.com/wp-content/uploads/2008/09/phpgccparse.png" alt="Picture of colored gcc output." title="phpgccparser" width="300" height="187" class="size-medium wp-image-71" /></a><p class="wp-caption-text">Picture of colored gcc output.</p></div><br />
To do this you&#8217;ll need <a href="http://php.net">PHP</a> installed on your machine. After that, the first step is to create a new command in TextMate&#8217;s C Bundle. Call it &#8220;Build, Format With PHP,&#8221; or anything else. Set it to save all files in the project when run [from the pull down at the top] now enter this into the text area:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">FILE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #800000;">${TM_FILEPATH}</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DIR</span>=<span style="color: #800000;">${TM_PROJECT_DIRECTORY}</span><br />
~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>TextMate<span style="color: #000000; font-weight: bold;">/</span>Support<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>make_format_gcc.sh</div></div>
<p>Next select Output as &#8220;Show as HTML&#8221; so we can see our output. Now create a file called &#8220;make_format_gcc.sh&#8221; in the folder ~/Library/Application Support/TextMate/Support/bin/<br />
Once you&#8217;ve created the file, use TM or vim to fill it with this:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #800000;">${FILE}</span>.mkout<br />
php <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>TextMate<span style="color: #000000; font-weight: bold;">/</span>Support<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gcc_format.php <span style="color: #800000;">${FILE}</span> <span style="color: #800000;">${DIR}</span></div></div>
<p>This bash script executes the make on the makefile and directs the standard and error output to the same file. Then the script calls php to parse and display the file. So now create a file named &#8220;gcc_format.php&#8221; in the same folder as make_format_gcc.sh and fill it with the meat of our parser:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// get stdout and stderr then delete temp file</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$commandFile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.mkout'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$commands</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$commandFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// break lines up by line ending</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$commands</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// find errors and link them to pages and line number</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$errors</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$fnpos</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">':'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fnpos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$lnpos</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/strpos"><span style="color: #990000;">strpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">': error:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$linestart</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lnpos</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$fnpos</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$linestart</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fnpos</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lnpos</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$fnpos</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;txmt://open/?url=file://<span style="color: #006699; font-weight: bold;">$dir</span>/<span style="color: #006699; font-weight: bold;">$filename</span>&amp;line=<span style="color: #006699; font-weight: bold;">$line</span>&amp;column=1&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr_replace"><span style="color: #990000;">substr_replace</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lnpos</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$link</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$lines</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$errors</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;br /&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lines</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'<br />
&nbsp; &nbsp; &lt;html&gt;<br />
&nbsp; &nbsp; &lt;head&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;style type=&quot;text/css&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; body &nbsp; &nbsp;{background:#000000; color:#999999;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; #comment{width:100%; background: #230021; color:#6060BF;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; #fail &nbsp; {width:100%; background:#3E0018; color:#9918B8;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; #succ &nbsp; {width:100%; background:#230021; color:#B0FFF0;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; dslsh &nbsp; {color:#A96AA9;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; a:link &nbsp;{color:#008080;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; a:hover {color:#80A0FF;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/style&gt;<br />
&nbsp; &nbsp; &lt;/head&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;body&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;comment&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;dslsh&gt;//&lt;/dslsh&gt; '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'\'s build results:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div id=&quot;fail&quot;&gt;Build failed with '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$errors</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">' errors.&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div id=&quot;succ&quot;&gt;Build Succeeded!&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span><span style="color: #0000ff;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/body&gt;<br />
&nbsp; &nbsp; &lt;/html&gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>This example assumes that you are working in a directory with a makefile, but I&#8217;m sure it can be easily modded to work with any build script. The colors reflect my favorite theme, but they should also be easily modded with lines 32-38 of the php script. Happy coding, peoples!</p>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/formatting-gcc-g-output-using-php-in-textmate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Auto Comment Block In TextMate</title>
		<link>http://efnx.com/auto-comment-block-in-textmate/</link>
		<comments>http://efnx.com/auto-comment-block-in-textmate/#comments</comments>
		<pubDate>Mon, 21 Jan 2008 09:34:14 +0000</pubDate>
		<dc:creator>Schell</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[auto-comment]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://blog.efnx.com/?p=43</guid>
		<description><![CDATA[If you haven&#8217;t heard of TextMate go check it out it&#8217;s sweet. It allows a helluva lot of automation and is damn near the only thing you need for development of any language [minus compilers]. I&#8217;m about ready to throw away my Flash CS3 IDE I got for free from my day job and shell [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t heard of TextMate go check it out <a href="http://macromates.com/">it&#8217;s sweet</a>. It allows a helluva lot of automation and is damn near the only thing you need for development of any language [minus compilers]. I&#8217;m about ready to throw away my Flash CS3 IDE I got for free from my day job and shell out the 39 pounds to buy it [those of you who know me personally know I don't ever buy software]. </p>
<p>So, here&#8217;s a little command I wrote in the form of a bash script [I think all textmate commands are bash scripts or cocoadialog thangs]. The script takes selected input and pads it with &#8220;/* */&#8221; if it isn&#8217;t already, effectively commenting the text or it strips the comment block. I don&#8217;t write shell scripts often, so I like it when I get one that&#8217;s really useful.</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------------</span><br />
<span style="color: #666666; font-style: italic;"># Make comment / Undo comment</span><br />
<span style="color: #666666; font-style: italic;"># by Schell Scivally</span><br />
<span style="color: #666666; font-style: italic;"># @ efnx.com</span><br />
<span style="color: #666666; font-style: italic;">#-------------------------------------------------------------------------</span><br />
<br />
<span style="color: #007800;">opening</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TM_SELECTED_TEXT</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'BEGIN {nlines=0} /\/\*/ {nlines++} END {print nlines}'</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$opening</span>&quot;</span> == <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;/*<span style="color: #007800;">$TM_SELECTED_TEXT</span>*/&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">output</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TM_SELECTED_TEXT</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\*\///g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\/\*//g'</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$output</span>&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://efnx.com/auto-comment-block-in-textmate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

