<?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>Ted Naleid &#187; osx</title>
	<atom:link href="http://naleid.com/blog/category/osx/feed/" rel="self" type="application/rss+xml" />
	<link>http://naleid.com/blog</link>
	<description>Groovy, Grails and OS X tips and tricks</description>
	<lastBuildDate>Wed, 16 Jun 2010 17:38:32 +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>Using a Unique Grails Working Directory for each Mercurial Branch</title>
		<link>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/</link>
		<comments>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/#comments</comments>
		<pubDate>Fri, 07 May 2010 18:07:40 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=184</guid>
		<description><![CDATA[At work, we&#8217;re using mercurial for our source control.  As we&#8217;ve released code to production we&#8217;ve needed to branch our repository to support what&#8217;s in production as well as ongoing development.  
By default, grails uses ~/.grails as the working directory.  If you&#8217;re doing branchy development, you can run into problems with this [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we&#8217;re using <a href="http://mercurial.selenic.com/" onclick="pageTracker._trackPageview('/outgoing/mercurial.selenic.com/?referer=');">mercurial</a> for our source control.  As we&#8217;ve released code to production we&#8217;ve needed to branch our repository to support what&#8217;s in production as well as ongoing development.  </p>
<p>By default, grails uses <code>~/.grails</code> as the working directory.  If you&#8217;re doing branchy development, you can run into problems with this if you&#8217;ve got plugins installed in one branch that aren&#8217;t in the other.  Having a unique directory per branch prevents you from having to run <code>grails clean</code> all the time.</p>
<p>Here&#8217;s a quick shell script that changes the grails working directory to have the branch name as a suffix if your source is contained in a mercurial repository (ex: the default branch would be <code>~/.grails_default</code> and the 1.0 branch would be <code>~/.grails_1.0</code>).  If your application is not in a repo, it just uses the regular <code>~/.grails directory</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">HG_BRANCH</span>=<span style="color: #000000; font-weight: bold;">`</span>hg branch <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">GRAILS_SCRIPT</span>=<span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>grails
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$HG_BRANCH</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">GRAILS_WORK_DIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> ~<span style="color: #000000; font-weight: bold;">`/</span>.grails_<span style="color: #007800;">$HG_BRANCH</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;** grails working directory: <span style="color: #007800;">$GRAILS_WORK_DIR</span>&quot;</span>
	<span style="color: #007800;">$GRAILS_SCRIPT</span> -Dgrails.work.dir=<span style="color: #007800;">$GRAILS_WORK_DIR</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;** default grails working directory&quot;</span>
	<span style="color: #007800;">$GRAILS_SCRIPT</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Just save this script as &#8220;grails&#8221; and put it in your PATH before the $GRAILS_HOME/bin directory (also make sure that you&#8217;ve defined $GRAILS_HOME).  I have a ~/bin directory that&#8217;s the first thing in my PATH.</p>
<p>If you use the grails-debug command, you can repeat these steps for that, just change <code>GRAILS_SCRIPT</code> to <code>$GRAILS_HOME/bin/grails-debug</code>.</p>
<p>This same technique could easily be modified to be used for other source control systems such as git or subversion.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grails Testing Alias to Rerun Failed Tests</title>
		<link>http://naleid.com/blog/2009/11/03/grails-testing-alias-to-rerun-failed-tests/</link>
		<comments>http://naleid.com/blog/2009/11/03/grails-testing-alias-to-rerun-failed-tests/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 03:29:58 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[zshrc]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=99</guid>
		<description><![CDATA[A while ago I blogged about my grails testing aliases and how much time they save me.
I&#8217;ve made some enhancements to them in the interim that have made them even easier to use.  
The most important alias is gtaf, which is short for &#8220;grails test-app&#8221; for failed tests.
It will search through your test output [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I <a href="http://naleid.com/blog/2009/06/14/grails-testing-command-line-aliases/">blogged about my grails testing aliases</a> and how much time they save me.</p>
<p>I&#8217;ve made some enhancements to them in the interim that have made them even easier to use.  </p>
<p>The most important alias is <code>gtaf</code>, which is short for &#8220;grails test-app&#8221; for failed tests.</p>
<p>It will search through your test output directory and look for any tests that failed.  If it finds any, it will rerun only those tests.  Otherwise, it will rerun all tests.  That makes it easy to just use <code>gtaf</code> all the time.  If any tests fail, it will open them up using Console.app.  </p>
<p>If you&#8217;re not on OSX, or would like to use something else to view the failed test logs, just modify the <code>testlog</code> alias to do something different.<br />
<span id="more-99"></span><br />
There are alternative versions of it to only run failed integration tests (<code>gtaif</code> &#8211; Grails Test App Integration Failed), failed unit tests (<code>gtauf</code> &#8211; Grails Test App Unit Failed) or attach a debugger to the tests as they run (<code>gtadf</code> &#8211; Grails Test App Debug Failed).</p>
<p>These aliases, plus most of the rest of my zsh setup, is <a href="http://bitbucket.org/tednaleid/shared-zshrc/src/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/src/?referer=');">available on bitbucket</a>.  If you haven&#8217;t used zsh before and are still using bash, I suggest <a href="http://naleid.com/blog/2009/05/13/shared-zshrc-file/">switching over for the numerous benefits that it gives you</a>.</p>
<p>Here&#8217;s the section of zshrc_general that has the grails testing aliases, just add this to your .zshrc/.bashrc and make sure to uncomment the appropriate GRAILS_TEST_LOG_DIRECTORY export if you&#8217;re not running grails 1.2 yet:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># grails &gt; 1.2</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GRAILS_TEST_LOG_DIRECTORY</span>=target<span style="color: #000000; font-weight: bold;">/</span>test-reports
&nbsp;
<span style="color: #666666; font-style: italic;"># grails &lt; 1.2</span>
<span style="color: #666666; font-style: italic;"># export GRAILS_TEST_LOG_DIRECTORY=test/reports</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># after grails-test if there were ERROR messages, you can open those logs with the Console.app using this</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">testlog</span>=<span style="color: #ff0000;">'for F in `grep -lE &quot;FAILED|Caused\ an\ ERROR&quot; $GRAILS_TEST_LOG_DIRECTORY/plain/*.txt`; do echo &quot;&gt;&gt;&gt; opening&quot; $F; open -a Console $F; done;'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># grails-debug-suspend doesn't exist by default, it's a copy of grails-debug with the suspend flag changed to &quot;y&quot; so that</span>
<span style="color: #666666; font-style: italic;"># we can attach a remote debugger before it proceeds past startup</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># aliases where you can optionally pass in a set of tests to run (or no argument to run all tests in that group)</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gta</span>=grailsTestApp
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtad</span>=grailsTestAppDebug
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtau</span>=grailsTestAppUnit
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaud</span>=grailsTestAppUnitDebug
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtai</span>=grailsTestAppIntegration
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaid</span>=grailsTestAppIntegrationDebug
&nbsp;
<span style="color: #666666; font-style: italic;"># aliases that will rerun any failed tests (or all tests if there aren't any failed tests)</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaf</span>=grailsTestAppFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtadf</span>=grailsTestAppDebugFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtauf</span>=grailsTestAppUnitFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaudf</span>=grailsTestAppUnitDebugFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaif</span>=grailsTestAppIntegrationFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaidf</span>=grailsTestAppIntegrationDebugFailed
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestApp<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails <span style="color: #ff0000;">&quot;&quot;</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppDebug<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails-debug-suspend <span style="color: #ff0000;">&quot;&quot;</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppDebugFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails-debug-suspend <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnit<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails <span style="color: #660033;">-unit</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnitFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails <span style="color: #660033;">-unit</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnitDebug<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails-debug-suspend <span style="color: #660033;">-unit</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnitDebugFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails-debug-suspend <span style="color: #660033;">-unit</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegration<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails <span style="color: #660033;">-integration</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegrationFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails <span style="color: #660033;">-integration</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegrationDebug<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails-debug-suspend <span style="color: #660033;">-integration</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegrationDebugFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails-debug-suspend <span style="color: #660033;">-integration</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsFailedTests<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #007800;">FAILED_TESTS</span>=<span style="color: #ff0000;">''</span>
	<span style="color: #000000; font-weight: bold;">for</span> F <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-lE</span> <span style="color: #ff0000;">&quot;FAILED|Caused\ an\ ERROR&quot;</span> <span style="color: #007800;">$GRAILS_TEST_LOG_DIRECTORY</span><span style="color: #000000; font-weight: bold;">/</span>plain<span style="color: #000000; font-weight: bold;">/*</span>.txt<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #007800;">FAILED_TESTS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$FAILED_TESTS</span> <span style="color: #780078;">`echo $F | sed -E 's/.*TEST-(.*)Tests.txt/\1/g'`</span>&quot;</span>
	<span style="color: #000000; font-weight: bold;">done</span>;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed tests: <span style="color: #007800;">$FAILED_TESTS</span>&quot;</span>
	grailsTest $<span style="color: #000000;">1</span> $<span style="color: #000000;">2</span> <span style="color: #007800;">$FAILED_TESTS</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTest<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Running: $1 test-app $2 $3 || testlog &quot;</span>
    <span style="color: #000000; font-weight: bold;">time</span> $<span style="color: #000000;">1</span> test-app $<span style="color: #000000;">2</span> $<span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">||</span> testlog
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>I believe that they&#8217;ll also work fine as-is in bash, though I haven&#8217;t tested them.</p>
<p><script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/11/03/grails-testing-alias-to-rerun-failed-tests/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Snow Leopard Shared Printer Job &#8220;On Hold: Authentication Required&#8221; fix</title>
		<link>http://naleid.com/blog/2009/11/01/snow-leopard-shared-printer-job-on-hold-authentication-required-fix/</link>
		<comments>http://naleid.com/blog/2009/11/01/snow-leopard-shared-printer-job-on-hold-authentication-required-fix/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 19:18:16 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=95</guid>
		<description><![CDATA[I&#8217;ve had problems since installing snow leopard with sharing my printer with my wife&#8217;s macbook pro.
Whenever she&#8217;d try to print, the job would say &#8220;On Hold: Authentication Required&#8221;.  After some fiddling around I found a solution:

Go into System Preferences and go to the Print &#038; Fax panel.
Right click on the printer and choose &#8220;Reset [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had problems since installing snow leopard with sharing my printer with my wife&#8217;s macbook pro.</p>
<p>Whenever she&#8217;d try to print, the job would say &#8220;On Hold: Authentication Required&#8221;.  After some fiddling around I found a solution:</p>
<ol>
<li>Go into System Preferences and go to the Print &#038; Fax panel.</li>
<li>Right click on the printer and choose &#8220;Reset Printing System&#8230;&#8221;.  This will remove all of your printers.</li>
<li>Hit the &#8220;+&#8221; and add the printer back, it should now be reset and have fixed whatever was fubar before.</li>
<li>Click on the &#8220;Sharing Preferences&#8221; button (or go to the &#8220;Sharing&#8221; System Preference panel)</li>
<li>Make sure that &#8220;Printer Sharing&#8221; is checked and that your printer&#8217;s name is also checked and that &#8220;Everyone&#8221; is set to &#8220;Can Print&#8221;</li>
<li>On the remote machine you want to remove the printer and add it back in through the System Preferences Print &#038; Fax panel</li>
</ol>
<p>(This is on 10.6.1, not sure if this works in 10.6.0 (where I first had the problem), you should update to the latest).</p>
<p>After doing all that, I was able to print from my remote computers without any problems or any issues around authentication.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/11/01/snow-leopard-shared-printer-job-on-hold-authentication-required-fix/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Poor Man&#8217;s &#8220;top&#8221; for MySQL</title>
		<link>http://naleid.com/blog/2009/06/18/poor-mans-top-for-mysql/</link>
		<comments>http://naleid.com/blog/2009/06/18/poor-mans-top-for-mysql/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 05:39:04 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=57</guid>
		<description><![CDATA[I&#8217;m currently working at a startup that&#8217;s small enough that we don&#8217;t have a dedicated DBA and I&#8217;ve been doing a lot of mysql maintenance work recently.  I wanted a quick dashboard for which commands were currently running and how long they&#8217;ve been running for.  Sort of like top but for mysql.
Combining the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working at a startup that&#8217;s small enough that we don&#8217;t have a dedicated DBA and I&#8217;ve been doing a lot of mysql maintenance work recently.  I wanted a quick dashboard for which commands were currently running and how long they&#8217;ve been running for.  Sort of like <a href="http://en.wikipedia.org/wiki/Top_(Unix)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Top_Unix?referer=');">top</a> but for mysql.</p>
<p>Combining the unix <a href="http://en.wikipedia.org/wiki/Watch_(Unix)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Watch_Unix?referer=');">&#8220;watch&#8221;</a> command with the mysql <a href="http://dev.mysql.com/doc/refman/5.1/en/show-processlist.html" onclick="pageTracker._trackPageview('/outgoing/dev.mysql.com/doc/refman/5.1/en/show-processlist.html?referer=');">&#8220;show processlist&#8221;</a> command gives me what I&#8217;m looking for.  A quick, self-updating status of the current state of the database.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">watch <span style="color: #660033;">-n</span> <span style="color: #000000;">5</span> <span style="color: #660033;">--differences</span> <span style="color: #ff0000;">&quot;mysql -u username -psekrit -e 'show processlist'&quot;</span></pre></div></div>

<p>Shows something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Every 5.0s: mysql <span style="color: #660033;">-n</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-u</span> username <span style="color: #660033;">-psekrit</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'show processlist'</span>                                   Thu Jun <span style="color: #000000;">18</span> 05:<span style="color: #000000;">25</span>:<span style="color: #000000;">14</span> <span style="color: #000000;">2009</span>
&nbsp;
Id      User    Host       db      Command Time    State         Info
<span style="color: #000000;">3141</span>    admin   localhost  mydb    Query   <span style="color: #000000;">34978</span>   freeing items SELECT <span style="color: #c20cb9; font-weight: bold;">id</span>, <span style="color: #7a0874; font-weight: bold;">type</span>, active, email FROM user WHERE email
<span style="color: #000000;">3146</span>    admin   localhost  mydb    Sleep   <span style="color: #000000;">0</span>                     NULL       
<span style="color: #000000;">24876</span>   root    localhost  NULL    Query   <span style="color: #000000;">0</span>       NULL          show processlist</pre></div></div>

<p>Where the &#8220;time&#8221; column is the number of seconds the query has been running, and Info holds the actual query (you can use &#8220;show full processlist&#8221; to see the full query).</p>
<p>Watch is a nice little linux util that runs a command every &#8220;n&#8221; seconds (it defaults to 2 seconds).  If you use the &#8211;differences switch, it will highlight the differences between one update and another.  I use watch for all kinds of monitoring activities, such as watching a directory to see a file grow in size as it gets transfered.</p>
<p>Here&#8217;s a quick shell function that you can add to your .bashrc/.bash_profile/.zshrc to use on arbitrary hosts:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mysqltop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">MYSQL_OPTS</span>=$<span style="color: #000000; font-weight: bold;">@</span>
    watch <span style="color: #660033;">-n</span> <span style="color: #000000;">5</span> <span style="color: #660033;">--differences</span> <span style="color: #ff0000;">&quot;mysql <span style="color: #007800;">$MYSQL_OPTS</span> -e 'show processlist'&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Then just pass in any creds/host info you need like a normal mysql command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqltop <span style="color: #660033;">-u</span> ted <span style="color: #660033;">-psekrit1</span> <span style="color: #660033;">-h</span> example.com <span style="color: #660033;">-P</span> <span style="color: #000000;">3307</span></pre></div></div>

<p>If you&#8217;re on linux, you probably already have &#8220;watch&#8221; installed.  If you&#8217;re on OSX, you probably don&#8217;t, but you can get it quickly through macports.  Install macports, make sure &#8220;port&#8221; is in your path and run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> watch</pre></div></div>

<p>There is also a command called <a href="http://jeremy.zawodny.com/mysql/mytop/" onclick="pageTracker._trackPageview('/outgoing/jeremy.zawodny.com/mysql/mytop/?referer=');">mytop</a> that you can get which looks like the same thing, but prints out the processlist details with some nicer formatting and a little extra information.  It&#8217;s in macports, but it has a number of dependencies including mysql so if you didn&#8217;t install mysql through macports, you might want to stick with what I have above or get it another way.</p>
<p>(EDIT: updated with bash function)</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/06/18/poor-mans-top-for-mysql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OSX AppleScript command line util to eject all removable disks</title>
		<link>http://naleid.com/blog/2009/05/26/osx-applescript-command-line-util-to-eject-all-removable-disks/</link>
		<comments>http://naleid.com/blog/2009/05/26/osx-applescript-command-line-util-to-eject-all-removable-disks/#comments</comments>
		<pubDate>Wed, 27 May 2009 03:16:28 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[eject]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=53</guid>
		<description><![CDATA[On my MacBook pro, I&#8217;ve got 4 removable hard drives (2 physical in 2 partitions each) and a JungleDisk mount.
I found it painful to manually eject each individual drive in the finder so I threw together this quick AppleScript to eject all the disks.

tell application &#34;Finder&#34;
	eject &#40;every disk&#41;
end tell

Just open up /Applications/AppleScript/ScriptEditor.app and paste that [...]]]></description>
			<content:encoded><![CDATA[<p>On my MacBook pro, I&#8217;ve got 4 removable hard drives (2 physical in 2 partitions each) and a <a href="http://www.jungledisk.com/" onclick="pageTracker._trackPageview('/outgoing/www.jungledisk.com/?referer=');">JungleDisk mount</a>.</p>
<p>I found it painful to manually eject each individual drive in the finder so I threw together this quick AppleScript to eject all the disks.</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Finder&quot;</span>
	<span style="color: #0066ff;">eject</span> <span style="color: #000000;">&#40;</span><span style="color: #ff0033;">every</span> <span style="color: #0066ff;">disk</span><span style="color: #000000;">&#41;</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></div></div>

<p>Just open up /Applications/AppleScript/ScriptEditor.app and paste that in.  Then choose &#8220;Save As&#8221; and pick &#8220;Application&#8221;.  That will compile the script and create a .app file that you can click on to run, or you can put it in your path and execute it there.</p>
<p>I think the same kind of script could be created with the command line &#8220;diskutil eject&#8221; command, but this seemed cleaner as I wasn&#8217;t able to come up with a generic way to figure out which disks were &#8220;ejectable&#8221; and which weren&#8217;t.  AppleScript is able to figure that all out for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/05/26/osx-applescript-command-line-util-to-eject-all-removable-disks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Shared zshrc file</title>
		<link>http://naleid.com/blog/2009/05/13/shared-zshrc-file/</link>
		<comments>http://naleid.com/blog/2009/05/13/shared-zshrc-file/#comments</comments>
		<pubDate>Wed, 13 May 2009 05:20:02 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[zshrc]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=52</guid>
		<description><![CDATA[Over the years, I&#8217;ve had a number of requests for me to share my zshrc file with friends and coworkers.  In the past, I&#8217;ve normally trimmed out the sensitive parts by hand and then e-mailed the most useful stuff.  I&#8217;ve always intended to make this an easier process and I&#8217;ve finally gotten around [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, I&#8217;ve had a number of requests for me to share my zshrc file with friends and coworkers.  In the past, I&#8217;ve normally trimmed out the sensitive parts by hand and then e-mailed the most useful stuff.  I&#8217;ve always intended to make this an easier process and I&#8217;ve finally gotten around to it.</p>
<p>I&#8217;ve created a new <a href="http://bitbucket.org/tednaleid/shared-zshrc/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/?referer=');">bitbucket repository to hold my shared zshrc configuration</a>.  You can get it for yourself by cloning the repository:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
hg clone http:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>tednaleid<span style="color: #000000; font-weight: bold;">/</span>shared-zshrc<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p><span id="more-52"></span><br />
If you don&#8217;t have mercurial installed, you can just <a href="http://bitbucket.org/tednaleid/shared-zshrc/downloads/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/downloads/?referer=');">grab the compressed archive of your choice from the downloads page</a>.</p>
<p>I&#8217;d suggest cloning/unzipping into your home directory, but you can put it wherever you want.</p>
<p>There&#8217;s an install.sh script in there that will create a new ~/.zshrc file.   If you have an existing .zshrc file, just move it out of the way and run the install script (it won&#8217;t let you whack an existing file).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>install.sh</pre></div></div>

<p>That created .zshrc file will load up all of my shared settings and aliases from wherever you have the shared-zshrc directory.  It also will look for a host specific file where any sensitive info, or host dependent info can be added.  I normally put things like my change directory and ssh aliases in here.</p>
<p>I probably created around half of these files myself, but I couldn&#8217;t tell you for the life of me where the majority of the other half came from.  This file has accreted over the years like barnacles on a ship.</p>
<p>Some of these commands originally started out in either a tcsh file (or was it ksh?), I eventually moved to bash, and then a couple of years ago, a coworker showed me the wonders of zsh and I haven&#8217;t looked back.</p>
<p>If you&#8217;re still using bash, give zsh a try.  Changing your shell is as easy as running this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chsh</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">zsh</span></pre></div></div>

<h2>ZSH Specific Stuff</h2>
<p>Most of the zsh shell configuration magic is in <a href="http://bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_compinstall" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_compinstall?referer=');">zshrc_compinstall</a>.  Some features include:</p>
<ul>
<li>shared history across shells</li>
<li>command spelling correction</li>
<li>vastly improved tab completion of commands (including keyboard navigation of potential matches)</li>
<li>file globbing that makes finding files easy (try <code>ls **/*.txt</code> to recursively search for all txt files, much easier than <code>find . -name "*.txt"</code></li>
<li>automatically using pushd for cd commands, use &#8220;dh&#8221; to see a history of your directories, use cd -N to go back N directories in your history (ex: <code>cd -3</code>)</li>
</ul>
<h2>Useful Aliases</h2>
<p>Some of the most useful aliases in <a href="http://bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_general" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_general?referer=');">zshrc_general</a> include:</p>
<h3>Grep through Aliases (ag)</h3>
<p>I often forget what some of my less often used aliases are, but I know what commands they use.  I&#8217;ve set up &#8220;ag&#8221; (alias grep) to help me search through my aliases and find the right one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> ag python
<span style="color: #007800;">webshare</span>=<span style="color: #ff0000;">'python -m SimpleHTTPServer'</span></pre></div></div>

<h3>Grepping History (gh)</h3>
<p>Great for finding commands in your history that you can only remember part of.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  gh grails
  ...
  <span style="color: #000000;">582</span>  grails create-app testDates
  <span style="color: #000000;">584</span>  grails create-domain-class Foo
  <span style="color: #000000;">585</span>  grails generate-all Foo
  <span style="color: #000000;">587</span>  <span style="color: #7a0874; font-weight: bold;">cd</span> grails-app
  <span style="color: #000000;">591</span>  grails generate-views Foo
  <span style="color: #000000;">592</span>  grails run-app</pre></div></div>

<h3>Global Alias &#8211; GV &#8211; to &#8220;grep -v&#8221;</h3>
<p>Grep is great for finding things, but often you find too much and need to slice stuff out.  If you use &#8220;grep -v&#8221; that finds all lines that <b>don&#8217;t</b> match a pattern.  The global alias &#8220;GV&#8221; that makes this even easier.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-ri</span> foo</pre></div></div>

<p>If that finds too much stuff (say catalina log files and svn files that you don&#8217;t care about), just slice them out with GV:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-ri</span> foo GV <span style="color: #c20cb9; font-weight: bold;">svn</span> GV catalina</pre></div></div>

<p>That will remove any lines that have &#8220;svn&#8221; or &#8220;catalina&#8221; anywhere in them (including the file name).</p>
<p>I think that rc files tend to be very personal things, what works for me likely won&#8217;t work for you exactly as it is.  But I also love to look at other people&#8217;s rc files to grab the things that look interesting.  Feel free to poke through mine and grab whatever strikes your fancy.</p>
<p>There&#8217;s a ton of other stuff in there that I use every day, including sections specific to version control (svn and hg) as well as groovy/grails shortcuts.  Feel free to poke around and ask me any questions about what something does.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/05/13/shared-zshrc-file/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enabling HTTPS support in curl installed through MacPorts on OSX</title>
		<link>http://naleid.com/blog/2009/03/16/enabling-https-support-in-curl-installed-through-macports-on-osx/</link>
		<comments>http://naleid.com/blog/2009/03/16/enabling-https-support-in-curl-installed-through-macports-on-osx/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 02:06:03 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=48</guid>
		<description><![CDATA[I ran into an issue today when trying to use curl to post something to an https endpoint on one of my Grails applications.  Apparently, recent macports versions of curl don&#8217;t have full ssl support enabled by default (I have no idea why, this seems like one of the basic use cases of curl).
This [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an issue today when trying to use curl to post something to an https endpoint on one of my Grails applications.  Apparently, recent macports versions of curl don&#8217;t have full ssl support enabled by default (I have no idea why, this seems like one of the basic use cases of curl).</p>
<p>This is what I was seeing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> curl <span style="color: #660033;">-k</span> https:<span style="color: #000000; font-weight: bold;">//</span>www.google.com
curl: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Protocol https not supported or disabled <span style="color: #000000; font-weight: bold;">in</span> libcurl</pre></div></div>

<p>After a bunch of fiddling around looking at the Portfile (located at <code>/opt/local/var/macports/sources/rsync.macports.org/release/ports/net/curl/Portfile</code>), I saw that there was something called a variant that seemed to talk about ssl support.  </p>
<p>I&#8217;d never needed to install a variant of a port before, but it&#8217;s actually pretty easy to do.  Just add a &#8220;+&#8221; with the variant name at the end of the install command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> curl +ssl</pre></div></div>

<p><span id="more-48"></span><br />
After that, curl did exactly what I was expecting it to:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> curl <span style="color: #660033;">-k</span> https:<span style="color: #000000; font-weight: bold;">//</span>www.google.com
<span style="color: #000000; font-weight: bold;">&lt;</span>HTML<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>HEAD<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>meta http-equiv=<span style="color: #ff0000;">&quot;content-type&quot;</span> <span style="color: #007800;">content</span>=<span style="color: #ff0000;">&quot;text/html;charset=utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>TITLE<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">302</span> Moved<span style="color: #000000; font-weight: bold;">&lt;/</span>TITLE<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>HEAD<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>BODY<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>H1<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">302</span> Moved<span style="color: #000000; font-weight: bold;">&lt;/</span>H1<span style="color: #000000; font-weight: bold;">&gt;</span>
The document has moved
<span style="color: #000000; font-weight: bold;">&lt;</span>A <span style="color: #007800;">HREF</span>=<span style="color: #ff0000;">&quot;http://www.google.com&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>here<span style="color: #000000; font-weight: bold;">&lt;/</span>A<span style="color: #000000; font-weight: bold;">&gt;</span>.
<span style="color: #000000; font-weight: bold;">&lt;/</span>BODY<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>HTML<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>So if you&#8217;ve already got curl installed with macports, you&#8217;ll probably want to uninstall it, then clean to be sure, then reinstall with the variant name:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port uninstall curl
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port clean curl
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> curl +ssl</pre></div></div>

<p>From the documentation, it appears that it also works for the upgrade command as well, so I believe you could force an upgrade and get it to install the curl ssl variant with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-f</span> upgrade curl +ssl</pre></div></div>

<p>I haven&#8217;t tested this though, so I can&#8217;t say with 100% certainty that it will work.  </p>
<p>UPDATE: Brian Michelich tried this and ran into some issues because he had git-core installed through macports.  Git-core relies on curl so forcing an upgrade could potentially bork anything that relies on curl.  The safest thing is likely to uninstall curl as macports will let you know if anything relies on it before you remove it.</p>
<p>If you want to check if you have any dependencies, you can use the &#8220;dependents&#8221; command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">port dependents curl</pre></div></div>

<p>I hope this helps someone (possibly me, in 6 months when I&#8217;m setting up my next computer :). </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/03/16/enabling-https-support-in-curl-installed-through-macports-on-osx/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Bash/Zsh aliases to switch Groovy and Grails version</title>
		<link>http://naleid.com/blog/2009/03/08/bashzsh-aliases-to-switch-groovy-and-grails-version/</link>
		<comments>http://naleid.com/blog/2009/03/08/bashzsh-aliases-to-switch-groovy-and-grails-version/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 00:58:34 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=46</guid>
		<description><![CDATA[I work on a couple of different grails projects that use a variety of versions of groovy and grails.  I&#8217;ve thrown together a quick shell script that makes it easy to create a new alias to switch between different versions depending on what project you&#8217;re working with.

function switchGrails&#40;&#41; &#123;
    echo &#34;Switching [...]]]></description>
			<content:encoded><![CDATA[<p>I work on a couple of different grails projects that use a variety of versions of groovy and grails.  I&#8217;ve thrown together a quick shell script that makes it easy to create a new alias to switch between different versions depending on what project you&#8217;re working with.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> switchGrails<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Switching to groovy version: $1&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Switching to grails version: $2&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>groovy,grails<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>groovy
    <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>grails
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done!&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-latr</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>groovy,grails<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">g104</span>=<span style="color: #ff0000;">'switchGrails &quot;groovy-1.5.7&quot; &quot;grails-1.0.4&quot;'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">g11rc2</span>=<span style="color: #ff0000;">'switchGrails &quot;groovy-1.6.0&quot; &quot;grails-1.1-RC2&quot;'</span></pre></div></div>

<p>You can create your own aliases like the ones above to switch to the groovy/grails combinations that you happen to be working with.  </p>
<p>Just stick the code above in your .profile/.bashrc/.zshrc file and restart your shell to make the aliases available.</p>
<p>This function assumes that you&#8217;ve got you&#8217;ve got groovy and grails installed in your /usr/local directory and that you use a symlink at /usr/local/groovy that $GROOVY_HOME is pointed to and /usr/local/grails that $GRAILS_HOME is pointed to.  If those assumptions aren&#8217;t correct for you, you&#8217;ll have to tweak the script.</p>
<p>It also uses &#8220;sudo&#8221; as it assumes that /usr/local is owned by root and not by your logged in user.  If you&#8217;ve chowned the directory to yourself, you can remove the sudo (and the need to enter your password).</p>
<p>Now it&#8217;s easy for me to switch between different projects by just typing the appropriate alias:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pollux<span style="color: #000000; font-weight: bold;">%</span> g104
Switching to groovy version: groovy-1.5.7
Switching to grails version: grails-1.0.4
Done<span style="color: #000000; font-weight: bold;">!</span>
lrwxr-xr-x  <span style="color: #000000;">1</span> root  wheel  <span style="color: #000000;">23</span> Mar  <span style="color: #000000;">8</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">55</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>groovy -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>groovy-1.5.7
lrwxr-xr-x  <span style="color: #000000;">1</span> root  wheel  <span style="color: #000000;">23</span> Mar  <span style="color: #000000;">8</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">55</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>grails -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>grails-1.0.4
&nbsp;
&nbsp;
pollux<span style="color: #000000; font-weight: bold;">%</span> g11rc2 
Switching to groovy version: groovy-1.6.0
Switching to grails version: grails-<span style="color: #000000;">1.1</span>-RC2
Done<span style="color: #000000; font-weight: bold;">!</span>
lrwxr-xr-x  <span style="color: #000000;">1</span> root  wheel  <span style="color: #000000;">23</span> Mar  <span style="color: #000000;">8</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">56</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>groovy -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>groovy-1.6.0
lrwxr-xr-x  <span style="color: #000000;">1</span> root  wheel  <span style="color: #000000;">25</span> Mar  <span style="color: #000000;">8</span> <span style="color: #000000;">19</span>:<span style="color: #000000;">56</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>grails -<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>grails-<span style="color: #000000;">1.1</span>-RC2</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/03/08/bashzsh-aliases-to-switch-groovy-and-grails-version/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Getting Grails New Uber Generate-All to Proceed without Prompting</title>
		<link>http://naleid.com/blog/2008/12/09/getting-grails-new-uber-generate-all-to-proceed-without-prompting/</link>
		<comments>http://naleid.com/blog/2008/12/09/getting-grails-new-uber-generate-all-to-proceed-without-prompting/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 22:20:43 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[generate all]]></category>
		<category><![CDATA[scaffolding]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=39</guid>
		<description><![CDATA[In my current project, I&#8217;ve been doing a lot of tweaking of the default grails scaffolding templates.  Because of this, I need to run the new uber generate-all command quite a bit to recreate things.
The one problem with this script is that if the files already exist, a prompt will come up after ~10 [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project, I&#8217;ve been doing a lot of tweaking of the default grails scaffolding templates.  Because of this, I need to run the new uber generate-all command quite a bit to recreate things.</p>
<p>The one problem with this script is that if the files already exist, a prompt will come up after ~10 seconds or so (after the grails environment bootstraps) asking you if you want to Overwrite everything:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails generate-all <span style="color: #ff0000;">&quot;*&quot;</span> 
...
~<span style="color: #000000;">10</span> seconds pass
...
Generating views <span style="color: #000000; font-weight: bold;">for</span> domain class Baz ...
File <span style="color: #000000; font-weight: bold;">/</span>foobar<span style="color: #000000; font-weight: bold;">/</span>grails-app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>baz<span style="color: #000000; font-weight: bold;">/</span>list.gsp already exists. Overwrite?y,n,a</pre></div></div>

<p>This was a bit of a pain as I&#8217;d often kick the script off, get distracted and then come back to the shell with that prompt still waiting for me to tell it what to do.  I&#8217;d rather just start working with my shiny new scaffolding.</p>
<p>The easy solution to this is simply to pipe the answer you want into the grails command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> grails generate-all <span style="color: #ff0000;">&quot;*&quot;</span></pre></div></div>

<p>Doing that will pipe the &#8220;a&#8221; into the grails command so that when the prompt finally comes up, it knows that it can continue regenerating all of my scaffolding.</p>
<p>It seems simple enough after I figured it out, but I thought it could save some other people time when they&#8217;re hacking around with templates and know they want to regenerate all of them.<br />
<span id="more-39"></span><br />
<script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2008/12/09/getting-grails-new-uber-generate-all-to-proceed-without-prompting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My Mercurial Setup (Plus Some Useful Shims and Jigs)</title>
		<link>http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/</link>
		<comments>http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 03:48:45 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[jig]]></category>
		<category><![CDATA[shim]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=37</guid>
		<description><![CDATA[In his book, The Productive Programmer, Neal Ford talks about using shims or jigs to help productivity.  Jigs and shims are quickly created little snippets of code that automate repetitive tasks or make them easy enough that they&#8217;re worth doing.  They&#8217;re little tools that help make your job easier and let you avoid [...]]]></description>
			<content:encoded><![CDATA[<p>In his book, <a href="http://productiveprogrammer.com/wiki/index.php/Main_Page" onclick="pageTracker._trackPageview('/outgoing/productiveprogrammer.com/wiki/index.php/Main_Page?referer=');">The Productive Programmer</a>, Neal Ford talks about using shims or jigs to help productivity.  Jigs and shims are quickly created little snippets of code that automate repetitive tasks or make them easy enough that they&#8217;re worth doing.  They&#8217;re little tools that help make your job easier and let you avoid using brute force to solve all of your problems.</p>
<p>My home directory has a bin folder in it that&#8217;s continually getting new jigs added to it, and my zshrc file is an ever-expanding list of quick shell functions.</p>
<p>Recently, I&#8217;ve been doing a lot more work with <a href="http://www.selenic.com/mercurial/wiki/" onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/?referer=');">Mercurial</a> as the team that I&#8217;m on switched from Subversion a couple of months ago on our Grails project.  The initial transition was a little difficult for some people, but I think just about everyone is pretty happy with the transition now that we&#8217;ve made it.  </p>
<p>Something that has helped everyone get comfortable with more complex Distributed Version Control System like Mercurial has been the distribution of shims and jigs amongst the team.  I thought these tips might be useful to others as well.<br />
<span id="more-37"></span></p>
<h2>Configuring Mercurial</h2>
<p>After installing mercurial (the easiest way is to just get the <a href="http://www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages" onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages?referer=');">appropriate binary package for your OS</a>), you&#8217;ll want to get it configured.</p>
<p>A good place to start is with someone else&#8217;s configuration file.  Here&#8217;s my my current ~/.hgrc configuration file (with the username replaced):</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[extensions] 
fetch=
extdiff=
color=
hgext.graphlog=
hgshelve=~/Documents/workspace/hgshelve/hgshelve.py
rdiff=~/Documents/workspace/rdiff/rdiff.py
hgext.mq =
&nbsp;
[diff]
git = 1
&nbsp;
[ui]
username = YOUR NAME &lt;YOUR_NAME@YOUR_COMPANY.com&gt;
&nbsp;
[extdiff]
cmd.kdiff3 =
cmd.chdiff =
opts.chdiff = --wait
&nbsp;
[merge-tools]
kdiff3.args = $base $local $other -o $output</pre></div></div>

<p>In it, you&#8217;ll see a number of useful extensions, including:</p>
<ul>
<li><code>hg fetch</code> &#8211; automates the pull/update working copy/merge/commit merge steps</li>
<li><code>extdiff extension</code> &#8211; Mercurial allows you to set up external tools to do diffs and merges.  I&#8217;m using 2 different graphical merge tools for different purposes</li>
<ul>
<li><code>hg chdiff</code> &#8211; <a href="http://changesapp.com/" onclick="pageTracker._trackPageview('/outgoing/changesapp.com/?referer=');">Changes.app</a> for just comparing two files in a diff.  Changes is a beautiful shareware diff tool for the mac, it unfortunately doesn&#8217;t do a <a href="http://en.wikipedia.org/wiki/Merge_(revision_control)#Three-way_merge" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Merge_revision_control_Three-way_merge?referer=');">3-way merge</a>.</li>
<li><code>hg kdiff3</code> &#8211; For merging, (and some diff situations), I need the power of a 3-way merge tool and I&#8217;ve found kdiff3 to be the best one that I&#8217;ve used.  It&#8217;s an open source, free, cross platform 3-way merge tool.  Using a 3-way merge tool is imperative for getting your merges correct.</li>
</ul>
<li><code>color extension</code> &#8211; just colorizes some output including the status command</a></li>
<li><code>hg glog</code> &#8211; an ascii graphical log of the commit tree (enhanced &#8220;hg log&#8221;)</li>
<li><code>hg shelve</code> &#8211; simplified patch management that allows you to &#8220;shelve&#8221; changes without committing them locally, for instance if you want to do a fetch, I asked about this on <a href="http://stackoverflow.com/questions/125272/using-mercurial-whats-the-easiest-way-to-commit-and-push-a-single-file-while-le" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/125272/using-mercurial-whats-the-easiest-way-to-commit-and-push-a-single-file-while-le?referer=');">Stack Overflow</a></li>
<li><code>hg rdiff</code> &#8211; remote diff, allows you to compare a file checked into your local repo with a file in the remote repository, I also asked about this on <a href="http://stackoverflow.com/questions/156280/using-mercurial-is-there-an-easy-way-to-diff-my-working-copy-with-the-tip-file" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/156280/using-mercurial-is-there-an-easy-way-to-diff-my-working-copy-with-the-tip-file?referer=');">Stack Overflow</a></li>
<li><code>mq extension</code> &#8211; mercurial queues, a more advanced topic that I don&#8217;t think anyone else at my workplace uses, but there&#8217;s a lot of power in mqueue if you look into it.  The Mozilla guys have a really <a href="https://developer.mozilla.org/en/Mercurial_Queues" onclick="pageTracker._trackPageview('/outgoing/developer.mozilla.org/en/Mercurial_Queues?referer=');">nice introductory tutorial</a> to using this plugin.</li>
</ul>
<h2>Setting up KDiff3 so you can do 3-way merges</h2>
<p>The simplest way to get KDiff3 is to <a href="http://kdiff3.sourceforge.net/" onclick="pageTracker._trackPageview('/outgoing/kdiff3.sourceforge.net/?referer=');">download the binary from the main website</a> (click on the download link and then choose the binary appropriate for your platform).</p>
<p>For the mac, you&#8217;ll just get a zip file with a KDiff3.app file in it that you should drag to your /Applications directory.  Then, you need to make sure that the actual executable in the application is in your path.  I just create a symlink in my path to the executable inside the application package:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>kdiff3.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>kdiff3 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>kdiff3</pre></div></div>

<p>You might not have /usr/local/bin in your path by default.  If you can execute <code>kdiff3 --help</code> on the command line, you&#8217;re ready to go.</p>
<h2>Setting up the &#8220;<a href='http://www.selenic.com/mercurial/wiki/index.cgi/ShelveExtension' onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/index.cgi/ShelveExtension?referer=');">shelve</a>&#8221; extension</h2>
<p>The easiest way to get the shelve extention set up is to simply clone the project that holds the python script to your local filesystem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone http:<span style="color: #000000; font-weight: bold;">//</span>freehg.org<span style="color: #000000; font-weight: bold;">/</span>u<span style="color: #000000; font-weight: bold;">/</span>tksoh<span style="color: #000000; font-weight: bold;">/</span>hgshelve<span style="color: #000000; font-weight: bold;">/</span> hgshelve</pre></div></div>

<p>Then just make sure that the path in your ~/.hgrc file points to the correct location of the hgshelve.py file in the cloned repository.</p>
<p>You can test that it&#8217;s working by just executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg <span style="color: #7a0874; font-weight: bold;">help</span> shelve</pre></div></div>

<p>If you don&#8217;t get an error message, it&#8217;s set up right and you can start using it.</p>
<h2>Setting up the &#8220;<a href='http://www.selenic.com/mercurial/wiki/index.cgi/RdiffExtension' onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/index.cgi/RdiffExtension?referer=');">rdiff</a>&#8221; extension</h2>
<p>Setting up the rdiff extension is similar to the shelve extension above.  Just clone the repository:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone <span style="color: #660033;">-r</span> c3ac1c497bf0 http:<span style="color: #000000; font-weight: bold;">//</span>hg.kublai.com<span style="color: #000000; font-weight: bold;">/</span>mercurial<span style="color: #000000; font-weight: bold;">/</span>extensions<span style="color: #000000; font-weight: bold;">/</span>rdiff</pre></div></div>

<p><strong>We clone an older revision currently as the tip in that project uses some unsupported stuff that isn&#8217;t in mercurial 1.0.2, if you&#8217;ve got a newer version of mercurial, you might be able to get the tip of the rdiff extension and have it work.<br />
</strong></p>
<p>Then make sure that your ~/.hgrc is pointed to the right path for the rdiff.py file in the repo you just cloned.</p>
<p>It&#8217;s a little quirky in that it actually modifies the existing &#8220;hg diff&#8221; command by detecting if the first parameter is a remote URL. If it is then it will diff that file against your tip file in your local repo (not the working copy). This as the remote repo is first in the arguments, it&#8217;s the reverse of what I&#8217;d expect, but you can pass &#8220;&#8211;reverse&#8221; to the hg diff command to switch that around.</p>
<p>I could see these being potential enhancements to the extension, but for now, I can work around them with a bash/zsh shell function in my startup file. It does a temp checkin of my working copy (held by the mercurial transaction so it can be rolled back), executes the reverse diff, and then rolls the transaction back to return things back to the way they were:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hgrdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    hg commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;temp commit for remote diff&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> 
    hg <span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">--reverse</span> http:<span style="color: #000000; font-weight: bold;">//</span>my_hardcoded_repo <span style="color: #007800;">$*</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>
    hg rollback      <span style="color: #666666; font-style: italic;"># revert the temporary commit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>And then call it with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hgrdiff <span style="color: #000000; font-weight: bold;">&lt;</span>filename to <span style="color: #c20cb9; font-weight: bold;">diff</span> against remote repo tip<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<h2>Other Mercurial Jigs and Shims</h2>
<p>Here are some other jigs and shims that I&#8217;ve found useful.</p>
<h4>Jig to Get a List of Files With the Same Status</h4>
<p>One jig that I&#8217;ve gotten a ton of use out of, is a modification to the normal &#8220;hg status&#8221; command.  Normally, &#8220;hg status&#8221; returns a list of all files that are different in the working directory when compared to the tip if the repository.  In the output of status, each file is printed with a character in the first column that signifies the status of that file.  Ex:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> hg status
M build.xml
A src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
A src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Quux.groovy
? src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy
? src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy</pre></div></div>

<p>Some of the most common statuses are:</p>
<ul>
<li><code>?</code> &#8211; not tracked, unknown to the source control repository
<li>
<li><code>M</code> &#8211; modified, this file is different in the working copy than on the file system
<li><code>A</code> &#8211; added, source control is aware of this file, but it hasn&#8217;t yet been committed
<li><code>R</code> &#8211; removed, this file has been marked for deletion on the next commit
<li><code>!</code> &#8211; missing, this file is not present in the working copy but is in source control
</ul>
<p>Often, I&#8217;ll want to do something with all of the files in a particular status, but I can&#8217;t easily do that as they&#8217;re mixed in with the other file types.  Also, the status flag at the beginning of the line prevents me from piping the status into another command.</p>
<p>I&#8217;ve come up with this shell function to allow me to filter lists of files (it actually works for subversion too, so there are 2 aliases).  Just paste this into your bash/zsh startup file:</p>
<pre code="bash">
vcst() {
	# print out all of the files with a passed in status flag (M - modified, A - added, ? - unknown, etc) (default ?)
	# expects first parameter to be the version control command (likely svn or hg)
	STATUS='\?'
	if [ -n "$2" ]
	then
		STATUS=$2
	fi
	$1 status | egrep "^$STATUS" | awk '{print $2}'
}

alias svnst='vcst svn'
alias hgst='vcst hg'
</pre>
<p>Then you can use the &#8220;hgst&#8221; command to see all the files in a particular status, one per line.  By default, it shows files that aren&#8217;t tracked (&#8220;<code>?</code>&#8220;), but you can pass a parameter that specifies another flag type if it&#8217;s other than &#8220;<code>?</code>&#8220;.</p>
<p>To see the list of files that aren&#8217;t in source control, just use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> hgst
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy</pre></div></div>

<p>If you want to delete all of the files that aren&#8217;t in source control, all you have to do is send the results of that command to rm:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">`</span>hgst<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># removes src/groovy/Bar.groovy and src/groovy/Baz.groovy</span></pre></div></div>

<p>If you want to edit all of the files that have been added in TextMate:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mate <span style="color: #000000; font-weight: bold;">`</span>hgst A<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># opens src/groovy/Foobar.groovy and src/groovy/Quux.groovy in TextMate</span></pre></div></div>

<p>If you want to do a diff and see only the files that have been modified using kdiff3:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg kdiff3 <span style="color: #000000; font-weight: bold;">`</span>hgst M<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># would show a diff of build.xml vs the working copy</span></pre></div></div>

<h4>Shim to See a List Incoming and Outgoing Files</h4>
<p>When I&#8217;m about to push changes out to a remote server, or pull changes down from that server, I often want to know what files will be affected by this action.  Surprisingly, there isn&#8217;t an easy built-in way to do this.</p>
<p>There is the <code>hg incoming -v</code> command, which will print out a log format of all of the different changesets.  But I don&#8217;t really care about all the changesets, I just want to know which files will be affected.  Here&#8217;s a sample run of incoming with 3 changesets:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> hg incoming <span style="color: #660033;">-v</span>
comparing with <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>ted.naleid<span style="color: #000000; font-weight: bold;">/</span>temp<span style="color: #000000; font-weight: bold;">/</span>foo
searching <span style="color: #000000; font-weight: bold;">for</span> changes
changeset:   <span style="color: #000000;">1</span>:5c5f71bda234
user:        Ted Naleid <span style="color: #000000; font-weight: bold;">&lt;</span>ted.naleid<span style="color: #000000; font-weight: bold;">@</span>carol.com<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">date</span>:        Tue Nov <span style="color: #000000;">25</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">30</span>:<span style="color: #000000;">51</span> <span style="color: #000000;">2008</span> <span style="color: #660033;">-0600</span>
files:       src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
description:
initial commit of foobar.groovy
&nbsp;
&nbsp;
changeset:   <span style="color: #000000;">2</span>:fe4a615747af
user:        Ted Naleid <span style="color: #000000; font-weight: bold;">&lt;</span>ted.naleid<span style="color: #000000; font-weight: bold;">@</span>carol.com<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">date</span>:        Tue Nov <span style="color: #000000;">25</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">36</span> <span style="color: #000000;">2008</span> <span style="color: #660033;">-0600</span>
files:       src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
description:
committing <span style="color: #000000;">2</span> files
&nbsp;
&nbsp;
changeset:   <span style="color: #000000;">3</span>:21e3d26bc3eb
tag:         tip
user:        Ted Naleid <span style="color: #000000; font-weight: bold;">&lt;</span>ted.naleid<span style="color: #000000; font-weight: bold;">@</span>carol.com<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">date</span>:        Tue Nov <span style="color: #000000;">25</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">54</span> <span style="color: #000000;">2008</span> <span style="color: #660033;">-0600</span>
files:       build.xml src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Quux.groovy
description:
3rd commit of files</pre></div></div>

<p>That&#8217;s not very useful as it&#8217;s hard to parse out the actual files in that list (and see only the unique list).</p>
<p>I use the following shim (just put in your bash/zsh rc file) to make this simple:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># look for lists of files in piped output, sort the unique set of them and print them one per line</span>
lf<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">&quot;^files:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{for (i=2; i&lt;=NF; i++) print $i}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> 
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ic</span>=<span style="color: #ff0000;">&quot;hg incoming -v | lf&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">og</span>=<span style="color: #ff0000;">&quot;hg outgoing -v | lf&quot;</span></pre></div></div>

<p>Once this is installed, you can simply use the <code>og</code> (outgoing) or <code>ic</code> (incoming) aliases to see what you&#8217;ll affect if you actually do a push or a pull.</p>
<p>Here&#8217;s the output using the incoming shim on same changeset above:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> ic
build.xml
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Quux.groovy</pre></div></div>

<p>That makes it quick and easy to see the real things that you&#8217;ll affect by your actions.</p>
<h4>Enhancing Your Shell Prompt With Mercurial Info</h4>
<p>A couple of other commands that I have in my zshrc (they should also work in a bash startup file):</p>
<pre>
hgtarget() {
    hg_root=`hg root 2>&#038;1 | egrep -v "$abort:"`
   	if [ $hg_root ]; then
    	if [ -f $hg_root/.hg/hgrc ]; then
        	hg_target=`cat $hg_root/.hg/hgrc | egrep "^default =" | sed 's/\(^default = \(http:\/\/\)*\)\(.*@\)*//'`
        	echo "$hg_target"
        fi
    fi
}

hgbranch() {
	hg_root=`hg root 2>&#038;1 | egrep -v "$abort:"`
	if [ $hg_root ]; then
		hg_branch=`hg branch`
		echo "$hg_branch"
	fi
}
</pre>
<p>These commands will tell you the path to the default push/pull target for your repository (<code>hgtarget</code>) as well as the current branch that you&#8217;re working on (<code>hgbranch</code>) in your repo.</p>
<p>I&#8217;ve added these to my shell prompt so that when I&#8217;m in a mercurial repository I&#8217;m more informed of the context that I&#8217;m working in.  My prompt is a little complicated (lots more going on there besides this), but there are a number of <a href="http://www.hypexr.org/bash_tutorial.php#cmd_prompt" onclick="pageTracker._trackPageview('/outgoing/www.hypexr.org/bash_tutorial.php_cmd_prompt?referer=');">good tutorials</a> out there for modifying yours.  </p>
<p><script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
