<?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>Eric Wendelin&#039;s Blog &#187; Tools</title>
	<atom:link href="http://eriwen.com/category/tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://eriwen.com</link>
	<description>Programming productively with open-source tools</description>
	<lastBuildDate>Thu, 26 Apr 2012 18:48:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Notes from my pursuit of the perfect front-end build</title>
		<link>http://eriwen.com/tools/perfect-front-end-build/</link>
		<comments>http://eriwen.com/tools/perfect-front-end-build/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 11:00:49 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://eriwen.com/tools/notes-from-my-pursuit-of-the-perfect-front-end-build/</guid>
		<description><![CDATA[I wrote previously about <a href="http://eriwen.com/tools/continuous-integration-for-javascript/">Continuous Integration for JavaScript</a> where I explained a build with <a href="http://jenkins-ci.org">Jenkins</a> and <a href="http://gradle.org">Gradle</a>. I've learned a lot since that article and thought it's now significant enough to write more on the topic.

<h2>Documentation</h2>
When you're writing code that other developers have to use or maintain, you ought to provide some amount of documentation. <strong>Your code is simply not self-documenting enough.</strong>

My favorite doc tool right now is <a href="https://github.com/senchalabs/jsduck">jsduck</a> developed by Sencha Labs for their Ext JS 4 docs. It basically consumes JSDoc-style comments (with some extras for namespaces, etc.) and generates beautiful documentation. Super easy to install and use:
 <a href="http://eriwen.com/tools/perfect-front-end-build/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/tools/wikify-yourself/' rel='bookmark' title='Why every programmer should have a Tiddlywiki'>Why every programmer should have a Tiddlywiki</a></li>
<li><a href='http://eriwen.com/tools/continuous-integration-for-javascript/' rel='bookmark' title='Continuous Integration for Javascript'>Continuous Integration for Javascript</a></li>
<li><a href='http://eriwen.com/javascript/text-size-prefs/' rel='bookmark' title='Guest Post: Save Text Size Preference Using MooTools and PHP'>Guest Post: Save Text Size Preference Using MooTools and PHP</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I wrote previously about <a href="http://eriwen.com/tools/continuous-integration-for-javascript/">Continuous Integration for JavaScript</a> where I explained a build with <a href="http://jenkins-ci.org">Jenkins</a> and <a href="http://gradle.org">Gradle</a>. I&#8217;ve learned a lot since that article and thought it&#8217;s now significant enough to write more on the topic.</p>
<h2>Documentation</h2>
<p>When you&#8217;re writing code that other developers have to use or maintain, you ought to provide some amount of documentation. <strong>Your code is simply not self-documenting enough.</strong></p>
<p>My favorite doc tool right now is <a href="https://github.com/senchalabs/jsduck">jsduck</a> developed by Sencha Labs for their Ext JS 4 docs. It basically consumes JSDoc-style comments (with some extras for namespaces, etc.) and generates beautiful documentation. Super easy to install and use:</p>
<pre class="brush: bash; title: ; notranslate">
gem install jsduck
jsduck src/js --output target/docs
</pre>
<h2>Use the Gradle wrapper</h2>
<p>Using the <a href="http://gradle.org/current/docs/userguide/gradle_wrapper.html">Gradle wrapper</a> allows users to build your project <strong>without installing Gradle</strong>, which is beautiful because it removes a very significant dependency for building and running your project.</p>
<p>Here&#8217;s how to use it. Add this to your <code>build.gradle</code> file:</p>
<pre class="brush: groovy; title: ; notranslate">
task wrapper(type: Wrapper) {
    // version of Gradle you want
    gradleVersion = '1.0-milestone-6'
}
</pre>
<p>Then you just have to run in your shell:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
gradle wrapper
</pre>
<p>and Gradle will add a few files to the project, most importantly <code>gradlew</code> and <code>gradlew.bat</code> (for Windows). These are binaries that your can run in lieu of <code>gradle</code>, and it wraps (obviously) the execution of Gradle such that it will download the correct version of Gradle and execute it locally. </p>
<p>I recommend that you switch to the Gradle wrapper when you have consumers of your project that may not have Gradle. I&#8217;m going to be doing this for all of my OSS projects from now on.</p>
<h2>Introducing the Gradle Web Suite</h2>
<p>Gradle really has building JVM-centric source down (for most languages), but I felt like it was cumbersome to operate on my web files with it. So I&#8217;ve written a collection of plugins that focus on making tasks with JavaScript, CSS, and other client-side tech dead simple.</p>
<pre class="brush: groovy; title: ; notranslate">
buildscript {
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath 'com.eriwen:gradle-css-plugin:0.2'
		classpath 'com.eriwen:gradle-js-plugin:0.2'
	}
}

apply plugin: 'css'
apply plugin: 'js'
</pre>
<p>And now we can use the tasks provided by these plugins:</p>
<pre class="brush: groovy; title: ; notranslate">
// Combine, minify and GZip CSS to teenytiny.css
css {
    input = fileTree(dir: &quot;${projectDir}/css&quot;, include: [&quot;file1.css&quot;, &quot;file2.css&quot;])
    output = file(&quot;${buildDir}/teenytiny.css&quot;)
}

// Same thing here, and look, file-globs :)
js {
    input = fileTree(dir: &quot;${projectDir}/js&quot;, include: &quot;**/*.js&quot;)
    output = file(&quot;${buildDir}/combinedMinifiedAndGzipped.js&quot;)
}

// ... and there's support for other tools like CSS Lint!
csslint {
	inputs.files fileTree(dir: &quot;${projectDir}/css&quot;, include: &quot;**/*.css&quot;)
	outputs.file file(&quot;${buildDir}/csslint.xml&quot;)
	options = [&quot;--rules=adjoining-classes,box-model&quot;, '--format=lint-xml']
}
</pre>
<p><a href="http://git.io/gradlecss">Gradle CSS Plugin</a> <iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=eriwen&#038;repo=gradle-css-plugin&#038;type=watch&#038;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="62px" height="20px"></iframe> | <a href="http://git.io/gradlejs">Gradle JS Plugin</a> <iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=eriwen&#038;repo=gradle-js-plugin&#038;type=watch&#038;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="62px" height="20px"></iframe></p>
<h2>JsTestDriver</h2>
<p>One tool I hadn&#8217;t paid enough attention to until recently was <a href="http://code.google.com/p/js-test-driver/" title="js-test-driver">JsTestDriver</a>. The awesome thing about it is that <strong>it has adapters for other JS testing frameworks like Jasmine</strong>. This is great because I don&#8217;t have to convert my tests (mostly) to JsTestDriver&#8217;s test API and I get crazy speed and reporting I wouldn&#8217;t otherwise get. </p>
<p>In a nutshell, JSTD is a testing tool developed by Google whereby you start as server and then &#8220;capture&#8221; browsers so that JSTD uploads tests to them, the browser runs tests and then sends back test results. This is awesome because it&#8217;s super fast and you can have it run every major browser simultaneously!</p>
<p>Here&#8217;s how you can use it. First, we need to <a href="http://code.google.com/p/js-test-driver/downloads/list">download JsTestDriver and the coverage plugin JARs</a>. Then we need a configuration file for JsTestDriver:</p>
<pre class="brush: plain; title: jsTestDriver.conf; notranslate">
server: http://localhost:4224

load:
  - lib/jasmine.js
  - lib/sinon-1.2.0.js
  - lib/jasmine-sinon.js
  - lib/JasmineAdapter.js
  - ../js/main.js

test:
  - spec/*.js

plugin:
  - name: &quot;coverage&quot;
    jar: &quot;lib/plugins/coverage.jar&quot;
    module: &quot;com.google.jstestdriver.coverage.CoverageModule&quot;
    args: useCoberturaFormat

timeout: 30
</pre>
<p>then we need to start the JSTD server:</p>
<pre class="brush: bash; title: ; notranslate">
java -jar path/to/JsTestDriver.jar --port 4224
</pre>
<p>Now we want to capture a browser by navigating it to <code>http://localhost:4224/capture</code>. Finally, run our tests with all captured browsers:</p>
<pre class="brush: bash; title: ; notranslate">
java -jar path/to/JsTestDriver.jar --tests all
</pre>
<p>and you should see something like this:</p>
<pre class="brush: plain; title: ; notranslate">
Chrome: Reset
.................
Total 17 tests (Passed: 17; Fails: 0; Errors: 0) (13.00 ms)
  Chrome 17.0.942.0 Mac OS: Run 17 tests (Passed: 17; Fails: 0; Errors 0) (13.00 ms)
/Users/eric/src/eriwen.com/test/spec/PageSpec.js: 95.789474% covered
/Users/eric/src/eriwen.com/test/lib/jasmine.js: 51.640926% covered
/Users/eric/src/eriwen.com/test/lib/sinon-1.2.0.js: 22.916668% covered
/Users/eric/src/eriwen.com/test/lib/jasmine-sinon.js: 73.333336% covered
/Users/eric/src/eriwen.com/test/lib/JasmineAdapter.js: 64.83517% covered
/Users/eric/src/eriwen.com/js/main.js: 60.15037% covered
</pre>
<p>And here&#8217;s how you can run it with Gradle:</p>
<pre class="brush: groovy; title: ; notranslate">
task jstd(type: Exec, dependsOn: 'init', description: 'runs JS tests through JsTestDriver') {
    // Default to MacOS and check for other environments
    def firefoxPath = '/Applications/Firefox.app/Contents/MacOS/firefox'
    if (&quot;uname&quot;.execute().text.trim() != 'Darwin') {
        firefoxPath = &quot;which firefox&quot;.execute().text
    }

    commandLine = ['/usr/bin/env', 'DISPLAY=:1', 'java', '-jar', &quot;${projectDir}/path/to/JsTestDriver.jar&quot;, '--config', &quot;${projectDir}/path/to/jsTestDriver.conf&quot;, '--port', '4224', '--browser', firefoxPath, '--tests', 'all', '--testOutput', buildDir]
}
</pre>
<p>Notice the coverage numbers? JSTD has generated a report in <a href="http://ltp.sourceforge.net/coverage/lcov.php">lcov</a> format, but this isn&#8217;t very readable to humans. </p>
<h2>Code Coverage!</h2>
<p>I couldn&#8217;t find any working scripts on the interwebs to convert the coverage file to Cobertura XML for reporting, so I wrote an <a href="https://github.com/eriwen/lcov-to-cobertura-xml">lcov-to-cobertura-xml</a> converter so we can report code coverage with <a href="http://jenkins-ci.org">Jenkins</a>!</p>
<p><img src="http://static.eriwen.com/images/coverage.png"/></p>
<p>And again with Gradle:</p>
<pre class="brush: groovy; title: ; notranslate">
task jsCoverage(type: Exec, dependsOn: 'jstd', description: 'JS code coverage with cobertura') {
	commandLine = ['python', &quot;${projectDir}/path/to/lcov-to-cobertura-xml.py&quot;, '-b', &quot;${projectDir}/&quot;, '-e', 'test.spec', '-e', 'test.lib', '-o', &quot;${buildDir}/coverage.xml&quot;, &quot;${buildDir}/jsTestDriver.conf-coverage.dat&quot;]
}
</pre>
<p>I talked about all of this at the <a href="http://www.therichwebexperience.com">Rich Web Experience</a> and I have some <a href="http://www.slideshare.net/emwendelin/javascript-ci">slides from my talk</a> that might be helpful if you want more detail about this stuff. </p>
<p><iframe src="http://www.slideshare.net/slideshow/embed_code/8688458" width="550" height="460" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="margin: 0 auto;"></iframe></p>
<h2>What about PhantomJS?</h2>
<p><a href="http://www.phantomjs.org/">PhantomJS</a> is still very necessary because JsTestDriver does NOT allow page or DOM interaction like Phantom does. I&#8217;m really excited about <a href="https://github.com/n1k0/casperjs">CasperJS</a> as it looks like a really nice way to do more functional testing with Phantom. I recommend you check it out.</p>
<h2>Conclusion</h2>
<p>You can see all of this in action in the <a href="https://github.com/eriwen/eriwen.com/blob/master/build.gradle">build for this very site</a>. </p>
<p>So that&#8217;s all I have for now. Let me know your experiences with these things or if there is something I missed, comment it up! Cheers!</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/tools/wikify-yourself/' rel='bookmark' title='Why every programmer should have a Tiddlywiki'>Why every programmer should have a Tiddlywiki</a></li>
<li><a href='http://eriwen.com/tools/continuous-integration-for-javascript/' rel='bookmark' title='Continuous Integration for Javascript'>Continuous Integration for Javascript</a></li>
<li><a href='http://eriwen.com/javascript/text-size-prefs/' rel='bookmark' title='Guest Post: Save Text Size Preference Using MooTools and PHP'>Guest Post: Save Text Size Preference Using MooTools and PHP</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/perfect-front-end-build/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Continuous Integration for Javascript</title>
		<link>http://eriwen.com/tools/continuous-integration-for-javascript/</link>
		<comments>http://eriwen.com/tools/continuous-integration-for-javascript/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 11:45:52 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=1364</guid>
		<description><![CDATA[<a href="http://jenkins-ci.org" title="Jenkins CI">Jenkins</a> is a <abbr title="Continuous Integration">CI</abbr> tool that is often used for Running tests and code analysis for Java and .NET projects. There are a lot of benefits that we as a community are not taking advantage of for our web (CSS, JS, etc) code. In this article I'm going to walk you through setting up automated building and testing for a JavaScript project.

<p class="update">NOTE: The steps outlined are generally Linux/Mac centric, I don't go into depth on Windows setup, but it shouldn't be much different using <a href="http://cygwin.com">Cygwin</a>.</p>

<h2>Why use CI?</h2>
Aside from the traditional benefits you see from your compiled code, there are some very compelling reasons:
<ol><li>Automate versioning, combining, minifying, and gzipping files</li>
<li>Run automated tests and get reports, keeping the codebase <strong>maintainable</strong></li>
<li>Run static analysis tools like the closure compiler or jshint</li>
<li>Auto-deploy files (to S3, say) if our build passes</li>
<li>Tag and other special stuff for release builds</li>
<li>... that's just JavaScript, we can also hook in Selenium tests, <a href="http://csslint.net">CSS Lint</a>, and more</li></ol>

Not convinced? <a href="#comments">Tell me why in the comments</a>.
 <a href="http://eriwen.com/tools/continuous-integration-for-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/stacktrace-update/' rel='bookmark' title='Javascript Stacktrace update'>Javascript Stacktrace update</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="update">I have posted more thoughts and tools on how to improve this <a href="http://eriwen.com/tools/perfect-front-end-build/" title="Notes from my pursuit of the perfect front-end build">here</a>.</p>
<p><a href="http://jenkins-ci.org" title="Jenkins CI">Jenkins</a> is a <abbr title="Continuous Integration">CI</abbr> tool that is often used for Running tests and code analysis for Java and .NET projects. There are a lot of benefits that we as a community are not taking advantage of for our web (CSS, JS, etc) code. In this article I&#8217;m going to walk you through setting up automated building and testing for a JavaScript project.</p>
<p class="update">NOTE: The steps outlined are generally Linux/Mac centric, I don&#8217;t go into depth on Windows setup, but it shouldn&#8217;t be much different using <a href="http://cygwin.com">Cygwin</a>.</p>
<h2>Why use CI?</h2>
<p>Aside from the traditional benefits you see from your compiled code, there are some very compelling reasons:</p>
<ol>
<li>Automate versioning, combining, minifying, and gzipping files</li>
<li>Run automated tests and get reports, keeping the codebase <strong>maintainable</strong></li>
<li>Run static analysis tools like the closure compiler or jshint</li>
<li>Auto-deploy files (to S3, say) if our build passes</li>
<li>Tag and other special stuff for release builds</li>
<li>And that&#8217;s not all!<sup>TM</sup> We can also hook in Selenium tests, <a href="http://csslint.net">CSS Lint</a>, and more</li>
</ol>
<p>Not convinced? <a href="#comments">Tell me why in the comments</a>.</p>
<h2>Jenkins setup</h2>
<p>Downloading and running Jenkins is incredibly easy. Just <a href="http://mirrors.jenkins-ci.org/war/latest/">download Jenkins</a> and run:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
java -jar jenkins.war
</pre>
<p>There are also native installers for most environments.</p>
<p>Now point your browser to <code>http://localhost:8080</code> to see it running.</p>
<p>Nailed it! Now we have a CI server!</p>
<h2>Prerequisites</h2>
<p>If we&#8217;re going to be using <a href="http://git-scm.org">git</a> and <a href="http://gradle.org">gradle</a>, we&#8217;ll need to install them (<a href="http://code.google.com/p/msysgit/downloads/list">Windows Git installer</a>). </p>
<pre class="brush: bash; title: Git language=installation; notranslate">
sudo yum install git-core  # CentOS/RedHat/etc
sudo apt-get install git   # Debian/Ubuntu/etc
sudo port install git-core # MacPorts
sudo brew install git      # Homebrew
</pre>
<pre class="brush: bash; title: Gradle language=installation; notranslate">
wget http://edub.me/ngMAeR # Gradle 1.0m3 ZIP
sudo mv gradle-1.0* /usr/local
sudo unzip /usr/local/gradle-1.0-milestone-3-bin.zip
sudo ln -s /usr/local/gradle-1.0-milestone-3 /usr/local/gradle
</pre>
<p>To tell Jenkins where to find Gradle, we go to <em>Manage Jenkins > Configure System</em> from the top page. Add a name and enter your GRADLE_HOME (/usr/local/gradle if you followed the instructions above). It should look like this:</p>
<p><img src="http://static.eriwen.com/images/jenkins-gradle-config-1.png" alt="Jenkins Gradle Setup"/></p>
<h2>Setup a CI job</h2>
<p>As an example, I&#8217;m going to use my <a href="https://github.com/eriwen/javascript-stacktrace" title="stacktrace.js project">stacktrace.js project on GitHub</a>. Even though it&#8217;s a small <abbr title="JavaScript">JS</abbr> library, almost all of the setup can be used for any type of project.</p>
<p>First, we want to install a few plugins that will help us out. We&#8217;ll need <a href="http://git-scm.org">Git</a> to pull down the code and <a href="http://www.gradle.org">Gradle</a> to build it. You&#8217;ll <strong>want the Git, Gradle, and Violations plugins installed</strong>. It&#8217;s pretty easy to figure out, but hit up the <a href="https://wiki.jenkins-ci.org/display/JENKINS/Use+Jenkins" title="Use Jenkins Wiki">Jenkins wiki</a> if you get stuck. </p>
<p>We want to create a new job that runs analysis on our JS and runs our tests. Click <em>New Job</em> on the Jenkins sidebar and you&#8217;ll see the setup form.</p>
<h2>Checking out and building a repo</h2>
<p>Under <em>Source Code Management</em> choose <em>Git</em> and enter <code>git://github.com/eriwen/javascript-stacktrace.git</code> for the repo location and <code>master</code> for the branch. It&#8217;ll look something like this:<br />
<img src="http://static.eriwen.com/images/jenkins-git-1.png" alt="Jenkins Git Setup"/></p>
<p>For the <em>Build</em> section of the setup, we want to run the <code>minify</code> build target from Gradle. You&#8217;ll also want to enter the location of the build file as <code>build/build.gradle</code>. Don&#8217;t worry about the contents of our build script right now, I have a slew of blog posts in-progress that explain it. <a href="http://eriwen.com/feed/">Stay tuned</a>.<br />
<img src="http://static.eriwen.com/images/jenkins-gradle-build.png" alt="Jenkins Gradle Minify"/></p>
<p>Now would be a good time to click <em>Save</em> at the bottom and then click <em>Build Now</em> on the sidebar for the job. You should see Jenkins checkout, pull down the latest Closure Compiler, and use it to minify stacktrace.js.</p>
<h2>Running JS unit tests with PhantomJS</h2>
<p>The days are past when you have to open a browser to see if your JS is generally working. <a href="http://www.phantomjs.org/" title="Headless Browser Testing">PhantomJS</a> is a headless WebKit browser that lets us interact with web pages (click links, pull from localStorage, etc.) without the browser window! This will let Jenkins run a browser with our tests and report the result. To follow along with the example, <a href="http://code.google.com/p/phantomjs/downloads/list">download</a> and install PhantomJS in <code>/usr/local/bin</code> (on Mac OS I just <code>sudo ln -s /Applications/phantomjs.app/Contents/MacOS/phantomjs /usr/local/bin/phantomjs</code>). Note that if you&#8217;re running Jenkins on a headless server, you&#8217;ll want to have <a href="http://en.wikipedia.org/wiki/Xvfb">xvfb</a>.</p>
<p>We also need to update the Build part of the configuration by telling gradle to run the <code>test</code> target.<br />
<img src="http://static.eriwen.com/images/jenkins-gradle-1.png" alt="Jenkins Gradle Setup"/></p>
<p>Gradle is now setup to run the <a href="http://docs.jquery.com/Qunit" title="QUnit Javascript Testing Framework">QUnit</a> tests in the project, but we need to tell Jenkins where to find the test reports. Easy! I encourage you to check out the <a href="https://github.com/eriwen/javascript-stacktrace/blob/master/build/build.gradle">source of build.gradle</a> if you want to know how this is setup. It&#8217;s really quite interesting.<br />
<img src="http://static.eriwen.com/images/jenkins-junit-1.png" alt="Jenkins JUnit Setup"/></p>
<p>Save and try that build again to bask in automated JavaScript testing awesomeness.</p>
<h2>Finding potential bugs with JSHint</h2>
<p>I&#8217;m a big fan of <a href="https://github.com/jshint/jshint/">JSHint</a> and I think it&#8217;s worthwhile to have it run on every <code>git push</code>. Here&#8217;s how to add that. To follow the example, you&#8217;ll have to install <a href="https://github.com/joyent/node/wiki/Installation">NodeJS</a> and the jshint module from <a href="http://npmjs.org" title="npm Is Not An Acronym">npm</a>:</p>
<pre class="brush: bash; light: true; title: Install 1=and 2=npm; notranslate">
sudo brew install node      # Homebrew
sudo port install node      # MacPorts
sudo apt-get install nodejs # Debian-based

curl http://npmjs.org/install.sh | sudo sh # Install NPM
sudo npm install -g jshint
</pre>
<p>Now we just need to tell Jenkins to run jshint as well as our tests and where to find the JSHint report. The gradle build puts it in <code>target/jshint.xml</code>. It should look like this:<br />
<img src="http://static.eriwen.com/images/jenkins-violations-1.png" alt="Jenkins Violations Setup"/><br />
<img src="http://static.eriwen.com/images/jenkins-jshint-1.png" alt="Jenkins JSHint Setup"/></p>
<p>One more <em>Build Now</em> and we have a fully functioning JavaScript build. You&#8217;ll also see graphs with test and jshint results on the job page and can drill down into details.</p>
<p>I have really loved my <abbr title="Continuous Integration">CI</abbr> setup for my web projects as well as my JVM-based ones. Now you have the power to go build a cool CI system for your projects. You can read more of my thoughts on this from my <a href="http://eriwen.com/tools/perfect-front-end-build/">notes from my pursuit of the perfect front-end build</a>. Enjoy!</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/stacktrace-update/' rel='bookmark' title='Javascript Stacktrace update'>Javascript Stacktrace update</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/continuous-integration-for-javascript/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Cheqlist: A free, open-source desktop app for Remember The Milk</title>
		<link>http://eriwen.com/tools/cheqlist-remember-the-milk-app/</link>
		<comments>http://eriwen.com/tools/cheqlist-remember-the-milk-app/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 11:00:34 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=939</guid>
		<description><![CDATA[<img src="http://eriwen.com/cheqlist/cheqlist_logo_64.png" style="float: left; margin: 0 8px 0 0; border: 0px solid none;"/>Anyone looking to stay productive with their work, errands or chores keeps a to-do list. You need to have that to-do list available at all times and be easy to manage. 

With that in mind, I am introducing an application that I think will help you with that: <a href="http://eriwen.com/cheqlist/Cheqlist.jnlp">Cheqlist</a>. A desktop application powered by <a href="http://www.rememberthemilk.com/">Remember The Milk</a> that does 2 things very well: make <strong>managing tasks very efficient</strong> and <strong>look sweet</strong> on your desktop.

<h2>What makes Cheqlist awesome</h2>
I wanted to build an application that I, myself, would use everyday. There are a few key features that would make that happen:
<ul style="margin-left: 2em; list-style-type: upper-roman;"><li>Adding tasks quickly using RTM's new <a href="<a href="http://www.rememberthemilk.com/services/smartadd/">Smart Add feature</a></li>
<li>Visual appeal and lots of room for customization. Special thanks to Rakesh Menon for allowing me to use his <a href="http://blogs.sun.com/rakeshmenonp/entry/javafx_color_picker">JavaFX color picker</a></li>
<li>Easily search tasks and use RTM's <a href="http://www.rememberthemilk.com/help/answers/search/advanced.rtm">custom search keywords</a></li>
<li>Must work on all the OSes I use: Windows, Mac OS X, and Linux</li>
</ul>

On top of that, I think there are some things you'll come to appreciate:
<ul style="margin-left: 2em; list-style-type: upper-roman;"><li>Easy-update: Cheqlist checks for updates on startup, and if you want to upgrade, it takes just seconds!</li>
<li>Free and <a href="http://github.com/emwendelin/cheqlist-javafx" title="Cheqlist at GitHub">open-source</a></li>
<li>Lots of nice "easter egg" features for those of you who take time to find them ;)</li></ul>
 <a href="http://eriwen.com/tools/cheqlist-remember-the-milk-app/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/groovy/introducing-groovyrtm/' rel='bookmark' title='Introducing GroovyRTM: A Groovier way to Remember The Milk'>Introducing GroovyRTM: A Groovier way to Remember The Milk</a></li>
<li><a href='http://eriwen.com/programming/the-tech-behind-cheqlist/' rel='bookmark' title='What and why: the tech behind Cheqlist'>What and why: the tech behind Cheqlist</a></li>
<li><a href='http://eriwen.com/productivity/multiple-desktops-to-get-things-done/' rel='bookmark' title='How I use multiple desktops to get things done'>How I use multiple desktops to get things done</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://eriwen.com/cheqlist/cheqlist_logo_64.png" style="float: left; margin: 0 8px 0 0; border: 0px solid none;"/>Anyone looking to stay productive with their work, errands or chores keeps a to-do list. You need to have that to-do list available at all times and be easy to manage. </p>
<p>With that in mind, I am introducing an application that I think will help you with that: <a href="http://eriwen.com/cheqlist/Cheqlist.jnlp">Cheqlist</a>. A desktop application powered by <a href="http://www.rememberthemilk.com/">Remember The Milk</a> that does 2 things very well: make <strong>managing tasks very efficient</strong> and <strong>look sweet</strong> on your desktop.</p>
<h2>What makes Cheqlist awesome</h2>
<p>I wanted to build an application that I, myself, would use everyday. There are a few key features that would make that happen:</p>
<ul style="margin-left: 2em; list-style-type: upper-roman;">
<li>Adding tasks quickly using RTM&#8217;s new <a href="<a href="http://www.rememberthemilk.com/services/smartadd/">Smart Add feature</a></li>
<li>Visual appeal and lots of room for customization. Special thanks to Rakesh Menon for allowing me to use his <a href="http://blogs.sun.com/rakeshmenonp/entry/javafx_color_picker">JavaFX color picker</a></li>
<li>Easily search tasks and use RTM&#8217;s <a href="http://www.rememberthemilk.com/help/answers/search/advanced.rtm">custom search keywords</a></li>
<li>Must work on all the OSes I use: Windows, Mac OS X, and Linux</li>
</ul>
<p>On top of that, I think there are some things you&#8217;ll come to appreciate:</p>
<ul style="margin-left: 2em; list-style-type: upper-roman;">
<li>Easy-update: Cheqlist checks for updates on startup, and if you want to upgrade, it takes just seconds!</li>
<li>Free and <a href="http://github.com/eriwen/cheqlist-javafx" title="Cheqlist at GitHub">open-source</a></li>
<li>Lots of nice &#8220;easter egg&#8221; features for those of you who take time to find them ;)</li>
</ul>
<h2>A quick look</h2>
<p>I&#8217;ve created a short (3 minutes) introductory video to show you the main features. UPDATE: Apparently screenr videos don&#8217;t show up in RSS properly. View it <a href="http://screenr.com/vvH" title="Cheqlist intro video">here</a>.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345' style='margin-left: 10px;'><param name='movie' value='http://screenr.com/Content/assets/screenr_0817090731.swf' /><param name='flashvars' value='i=18211' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_0817090731.swf' flashvars='i=18211' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p>Here are a few screenshots:<br />
<img src="http://eriwen.com/images/cheqlist_screen_1.png" alt="Cheqlist Splash Screen and Edit panes"/><br />
<img src="http://eriwen.com/images/cheqlist_screen_2.png" alt="Cheqlist Settings"/></p>
<p>You can find more on the <a href="http://wiki.github.com/eriwen/cheqlist-javafx/">Cheqlist Wiki</a>.</p>
<h2>Try it out!</h2>
<p>What you need:</p>
<ul style="margin-left: 2em; list-style-type: upper-roman;">
<li>A marginally recent (6u11 or newer) version of <a href="http://www.java.com/en/download/index.jsp" title="Download Java">Java</a></li>
<li><a href="http://www.rememberthemilk.com/">Remember The Milk account</a></li>
<li><strong><a href="http://eriwen.com/cheqlist/Cheqlist.jnlp">Launch Cheqlist</a></strong></li>
</ul>
<h2>Other resources</h2>
<p>Something missing? Request a feature at the <a href="http://github.com/eriwen/cheqlist-javafx/issues" title="Cheqlist issue tracker">issue tracker</a>. </p>
<p>Having trouble? <a href="http://eriwen.com/contact/">Let me know</a> directly. </p>
<p>For more information, you can hit the <a href="http://github.com/eriwen/cheqlist-javafx">project page</a> and <a href="http://wiki.github.com/eriwen/cheqlist-javafx/">Wiki</a> on GitHub. </p>
<p>Enjoy!</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/groovy/introducing-groovyrtm/' rel='bookmark' title='Introducing GroovyRTM: A Groovier way to Remember The Milk'>Introducing GroovyRTM: A Groovier way to Remember The Milk</a></li>
<li><a href='http://eriwen.com/programming/the-tech-behind-cheqlist/' rel='bookmark' title='What and why: the tech behind Cheqlist'>What and why: the tech behind Cheqlist</a></li>
<li><a href='http://eriwen.com/productivity/multiple-desktops-to-get-things-done/' rel='bookmark' title='How I use multiple desktops to get things done'>How I use multiple desktops to get things done</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/cheqlist-remember-the-milk-app/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Why every programmer should have a Tiddlywiki</title>
		<link>http://eriwen.com/tools/wikify-yourself/</link>
		<comments>http://eriwen.com/tools/wikify-yourself/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 14:00:42 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=33</guid>
		<description><![CDATA[A year ago, my good friend <a href="http://casedogdesigns.com">Casey Watson</a> suggested that I try using a personal wiki to keep track of my programming knowledge. This turned out to be great advice, so I'll be sharing how I use one and how to start your own.

<h2>Why would a personal wiki make you productive?</h2>
In a phrase: to keep a your web of knowledge accessible from one place. You need a place to put your meeting agenda, important project/server links, and even a to-do or waiting-for list. Not only can you store a lot, you can tag it, search it and otherwise customize the crap out of <a href="http://www.tiddlywiki.com/">Tiddlywiki</a>.

<img src="http://static.eriwen.com/images/eriki.gif" alt="Eric's Tiddlywiki" style="float:left; margin: 0 12px 12px 0;" width="222" height="202"/>You are not going to be able to remember everything you need, <strong>keeping links and information in email folders just doesn't cut it</strong>. You can easily keep track of your meeting notes, DB schema diagrams, bug lists, blah blah blah... <a href="http://eriwen.com/tools/wikify-yourself/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/productivity/find-is-a-beautiful-tool/' rel='bookmark' title='Find is a beautiful tool'>Find is a beautiful tool</a></li>
<li><a href='http://eriwen.com/tools/get-sed-savvy-2/' rel='bookmark' title='Get sed savvy &#8211; part 2'>Get sed savvy &#8211; part 2</a></li>
<li><a href='http://eriwen.com/firefox/my-firefox-setup/' rel='bookmark' title='8 steps to my personal Firefox setup for productivity'>8 steps to my personal Firefox setup for productivity</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A year ago, my good friend <a href="http://casedogdesigns.com">Casey Watson</a> suggested that I try using a personal wiki to keep track of my programming knowledge. This turned out to be great advice, so I&#8217;ll be sharing how I use one and how to start your own.</p>
<h2>Why would a personal wiki make you productive?</h2>
<p>In a phrase: to keep a your web of knowledge accessible from one place. You need a place to put your meeting agenda, important project/server links, and even a to-do or waiting-for list. Not only can you store a lot, you can tag it, search it and otherwise customize the crap out of <a href="http://www.tiddlywiki.com/">Tiddlywiki</a>.</p>
<p><img src="http://static.eriwen.com/images/eriki.gif" alt="Eric's Tiddlywiki" style="float:left; margin: 0 12px 12px 0;" width="222" height="202"/>You are not going to be able to remember everything you need, <strong>keeping links and information in email folders just doesn&#8217;t cut it</strong>. You can easily keep track of your meeting notes, DB schema diagrams, bug lists, blah blah blah&#8230;</p>
<p>In other news, great programmers <a href="http://www.agiledeveloper.com/blog/">Venkat Subramaniam</a> and Mark Richards called Tiddlywiki their favorite technical tool. <strong>Favorite.</strong> As in more valuable than their IDE. </p>
<h2>Roll your own&#8230; now!</h2>
<p>It&#8217;s really stinkin&#8217; easy! Just grab my favorite flavor of Tiddlywiki, <a href="http://www.dcubed.ca/Welcome_to_d-cubed.html">d-cubed</a>, and save it somewhere you can access easily. The first time you use it your browser will ask you to confirm that you can edit your HTML file through it (standard security check). </p>
<p>You will probably want to theme it so it fits you, and I found a bunch of nice themes at <a href="http://tiddlythemes.com/" title="Themes for TiddlyWiki">TiddlyThemes</a>. It&#8217;s just CSS and JavaScript anyway, dowhatyouwant! whatyouwant!!</p>
<p>Once you have customized your wiki&#8217;s look-and-feel etc., it&#8217;s time to grab some slick plugins. Here are a few I use and recommend:</p>
<ul style="list-style-type: upper-roman; margin-left: 3em;">
<li><a href="http://www.tiddlytools.com/#CheckboxPlugin">Checkbox plugin</a> &#8211; So you can manage your tasks with checkbox style</li>
<li><a href="http://www.tiddlytools.com/#CalendarPlugin">Calendar plugin</a> and <a href="http://www.tiddlytools.com/#DatePlugin">Date plugin</a> &#8211; Manage your calendar in your wiki!</li>
<li><a href="http://tiddlywiki.abego-software.de/#YourSearchPlugin">Your Search plugin</a> &#8211; Really, really sweet search upgrade. A must-grab!</li>
</ul>
<p>To install a plugin, just make a new Tiddler (wiki page) with the same title, content, and tags. So easy!</p>
<h2>Next steps</h2>
<p>I recommend starting by creating tiddlers for all your projects and just putting links to other resources in there. After awhile, copy bits of emails you need to remember to relevant places so you can search it anytime. Baby steps, but <strong>stick to it</strong>. The setup cost will be returned in cases (as in the beer others will buy you for rocking)!</p>
<p>You&#8217;re now well on your way to wiki-fying yourself. Share your experiences and have fun!</p>
<p class='update'><strong>Oh, hai Hacker News!</strong> You should note that this article is almost 3 years old but nevertheless I still use Tiddlywiki! I sync it with my <a href='http://db.tt/uTTF6nk'>Dropbox</a> account, which syncs it across all of my environments as well as keeps the last few versions. I recommend that, too.</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/productivity/find-is-a-beautiful-tool/' rel='bookmark' title='Find is a beautiful tool'>Find is a beautiful tool</a></li>
<li><a href='http://eriwen.com/tools/get-sed-savvy-2/' rel='bookmark' title='Get sed savvy &#8211; part 2'>Get sed savvy &#8211; part 2</a></li>
<li><a href='http://eriwen.com/firefox/my-firefox-setup/' rel='bookmark' title='8 steps to my personal Firefox setup for productivity'>8 steps to my personal Firefox setup for productivity</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/wikify-yourself/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>Vim is a beautiful tool</title>
		<link>http://eriwen.com/tools/vim-is-a-beautiful-tool/</link>
		<comments>http://eriwen.com/tools/vim-is-a-beautiful-tool/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 12:00:49 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=232</guid>
		<description><![CDATA[<p class="update" style="margin-right: 90px">This post was authored by guest author <a href="http://marksanborn.net">Mark Sanborn</a>. Find out more <a href="http://eriwen.com/tools/vim-is-a-beautiful-tool/#markbio">below</a>.</p>

When it comes to productivity I can't think of any application that has saved more time and frustration than Vim.  Vim is the ultimate productivity tool for programmers.  Most users of Vim that I know that have spent the time to learn it absolutely love it and couldn't imagine a world without it.  My only regret with Vim is not learning it sooner.

<h2>So what is Vim?</h2>

Vim is a modal text editor that is highly configurable, efficient, and lightweight.  Some people refer to it as the programmer's text editor because it has a plethora of features that make programming easier, although it could be used for other things like writing email and editing config files.

What makes Vim especially great is the shortcuts, commands, and the blistering speed at which you can edit text files since Vim has all the common editing tasks mapped to single keys on or near the home row on your keyboard.

Sounds great... but there is a catch:  <blockquote>Vim isn't an editor designed to hold its users' hands. It is a tool, the use of which must be learned.</blockquote>

<h2>Easing the learning curve</h2>

Vim is known for having a steep learning curve.  I think Vim has this reputation because people tend to want to learn all of the features right away and quickly become overwhelmed.

Vim is a lot like Adobe Photoshop, you can learn just a few simple techniques in Photoshop that can make a world of a difference in the images you can create and ways you can manipulate them.  Yet it may take you a lifetime to master all the functions Photoshop has to offer.  Vim is the same way.  You can learn only a few shortcuts and commands that will completely change the way you do text editing but may take years to learn them all (not that you would need to).

The great thing about Vim is everyone uses it differently.  I have my favorite shortcuts that I use every day.  Someone else might have a different set they use depending on what types of files they generally edit.  Once you learn a few basics and get comfortable with the shortcuts and commands that you use every day you can learn another to increase your productivity.

<h2>Getting Started</h2>

I suggest going through <strong>vimtutor</strong> once right now and again after you have played around with Vim for a while.  You can access vimtutor by typing in the command, 'vimtutor' for Linux users and by running vimtutor.bat in your Vim folder for Windows users.

Vimtutor has all the commands and how to use them as well as practice sections for all your basic editing needs.  Don't worry if you don't remember all the commands when going through the vimtutor for the first time; however, it is important to do the exercises at the end of each section so you can get used to the way Vim works.  It should only take about a half hour to make it through your first run through the tutorial.

You might consider bookmarking this article for your reference and checking out vimtutor now.

<h2>Making Vim Work for You</h2>

After using Vim for a while now I have a good idea which commands I use most often when doing web development, programming, and configuration editing.  We will use this experience to look at different ways Vim can improve your programming and make it faster while trying not to overwhelm you with too many new commands.  Grab a few of these, use them, and add more when you feel comfortable.
 <a href="http://eriwen.com/tools/vim-is-a-beautiful-tool/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/tools/awk-is-a-beautiful-tool/' rel='bookmark' title='awk is a beautiful tool'>awk is a beautiful tool</a></li>
<li><a href='http://eriwen.com/tools/grep-is-a-beautiful-tool/' rel='bookmark' title='grep is a beautiful tool'>grep is a beautiful tool</a></li>
<li><a href='http://eriwen.com/productivity/find-is-a-beautiful-tool/' rel='bookmark' title='Find is a beautiful tool'>Find is a beautiful tool</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="update" style="margin-right: 92px">This post was authored by guest author <a href="http://marksanborn.net">Mark Sanborn</a>. Find out more <a href="http://eriwen.com/tools/vim-is-a-beautiful-tool/#markbio">below</a>.</p>
<p>When it comes to productivity I can&#8217;t think of any application that has saved more time and frustration than Vim.  Vim is the ultimate productivity tool for programmers.  Most users of Vim that I know that have spent the time to learn it absolutely love it and couldn&#8217;t imagine a world without it.  My only regret with Vim is not learning it sooner.</p>
<h2>So what is Vim?</h2>
<p>Vim is a modal text editor that is highly configurable, efficient, and lightweight.  Some people refer to it as the programmer&#8217;s text editor because it has a plethora of features that make programming easier, although it could be used for other things like writing email and editing config files.</p>
<p>What makes Vim especially great is the shortcuts, commands, and the blistering speed at which you can edit text files since Vim has all the common editing tasks mapped to single keys on or near the home row on your keyboard.</p>
<p>Sounds great&#8230; but there is a catch:<br />
<blockquote>Vim isn&#8217;t an editor designed to hold its users&#8217; hands. It is a tool, the use of which must be learned.</p></blockquote>
<h2>Easing the learning curve</h2>
<p>Vim is known for having a steep learning curve.  I think Vim has this reputation because people tend to want to learn all of the features right away and quickly become overwhelmed.</p>
<p>Vim is a lot like Adobe Photoshop, you can learn just a few simple techniques in Photoshop that can make a world of a difference in the images you can create and ways you can manipulate them.  Yet it may take you a lifetime to master all the functions Photoshop has to offer.  Vim is the same way.  You can learn only a few shortcuts and commands that will completely change the way you do text editing but may take years to learn them all (not that you would need to).</p>
<p>The great thing about Vim is everyone uses it differently.  I have my favorite shortcuts that I use every day.  Someone else might have a different set they use depending on what types of files they generally edit.  Once you learn a few basics and get comfortable with the shortcuts and commands that you use every day you can learn another to increase your productivity.</p>
<h2>Getting Started</h2>
<p>I suggest going through <strong>vimtutor</strong> once right now and again after you have played around with Vim for a while.  You can access vimtutor by typing in the command, &#8216;vimtutor&#8217; for Linux users and by running vimtutor.bat in your Vim folder for Windows users.</p>
<p>Vimtutor has all the commands and how to use them as well as practice sections for all your basic editing needs.  Don&#8217;t worry if you don&#8217;t remember all the commands when going through the vimtutor for the first time; however, it is important to do the exercises at the end of each section so you can get used to the way Vim works.  It should only take about a half hour to make it through your first run through the tutorial.</p>
<p>You might consider bookmarking this article for your reference and checking out vimtutor now.</p>
<h2>Making Vim Work for You</h2>
<p>After using Vim for a while now I have a good idea which commands I use most often when doing web development, programming, and configuration editing.  We will use this experience to look at different ways Vim can improve your programming and make it faster while trying not to overwhelm you with too many new commands.  Grab a few of these, use them, and add more when you feel comfortable.</p>
<h2>Vim modes</h2>
<p>In Vim there are three major modes:</p>
<ul>
<li><strong>Insert mode</strong> is like the Windows &#8216;notepad&#8217;.  Simply type and text will output to the screen.</li>
<li><strong>Command mode</strong> is where Vim really shines.  This mode is usually called &quot;normal mode&quot; since you will be using this mode a lot.  To get into Command mode just hit &#8216;Esc&#8217;.  When in command mode almost all letters numbers and keys on the keyboard are now shortcuts.  The keys, &#8216;hjkl&#8217; in command mode are now your &quot;arrow keys&quot;.</li>
<li><strong>Visual mode</strong> is where you can highlight text.</li>
</ul>
<p>If you ever made a mistake and hit the wrong key you can use &#8216;<strong>Esc</strong>&#8216; to get back to normal mode.</p>
<h2>Commands by function</h2>
<p><strong>Note:</strong> As with other *nix tools, these commands are case sensitive.<br />
You can use these commands in conjunction with another command or repeated x number of times by adding a digit to the beginning. For example, &#8216;<strong>4dd</strong>&#8216; would delete 4 lines.  &#8216;<strong>dw</strong>&#8216; would delete a word.</p>
<p>Here are some of the most common vim commands and their meanings:  </p>
<h2>Open and save:</h2>
<p>&#8216;<strong>:e path/to/filename</strong>&#8216; &#8211; With Vim running, this will open the file you specify.  This command can also be used to open remote files over SSH.<br />
&#8216;<strong>:w</strong>&#8216; &#8211; Will save the current file<br />
&#8216;<strong>:q</strong>&#8216; &#8211; Exits Vim</p>
<p>You can also use these commands together:</p>
<p>&#8216;<strong>:wq</strong>&#8216; &#8211; Writes to the file and exits Vim</p>
<p>If you want to quit without saving your changes you can do</p>
<p>&#8216;<strong>:q!</strong>&#8216; &#8211; Quit without saving</p>
<h2>Moving Around:</h2>
<p>To move your cursor around with vim you will use:</p>
<p><strong>h</strong> &#8211; left<br />
<strong>j</strong> &#8211; down<br />
<strong>k</strong> &#8211; up<br />
<strong>l</strong> &#8211; right</p>
<p>These movement keys are all located on the home row.  It will take a little getting used to but you will thank yourself for not using arrows or the mouse when you realize much time is wasted moving your hands.  I even find myself trying to use these keys in other programs and get frustrated when they don&#8217;t work.  Sometimes I am pleasantly surprised when programs can be navigated with these keys.</p>
<h3>Undo and Redo:</h3>
<p>Of course you can&#8217;t have an editor without undo and redo.</p>
<p><strong>u</strong> &#8211; undo the last change<br />
<strong>U</strong> &#8211; undo all changes on that line.  This is very useful when programming.<br />
<strong>Ctrl + r</strong> &#8211; redo the last change</p>
<h2>Copy and Paste:</h2>
<p>You will probably find yourself wanting to copy and paste at some point.  I will first explain how to copy and paste lines of text in the way that you are used to and then describe a few alternative ways.</p>
<p>To highlight the text you want to copy you will need to put Vim into visual mode.  You can do this different ways.</p>
<p><strong>v</strong> &#8211; go into visual mode and highlight with the Vim movement keys.<br />
<strong>V</strong> &#8211; go into visual mode and highlight lines of text</p>
<p>Once you have the text highlighted you will then &quot;yank&quot; the text with the &#8216;y&#8217; key.</p>
<p><strong>y</strong> &#8211; yank (copy) text.</p>
<p>Once you have the text yanked (copied) you can &quot;put&quot; (paste) it with the &#8216;p&#8217; key.</p>
<p><strong>p</strong> &#8211; put/paste text.</p>
<p>So far Vim has failed to show any real improvements over the way you are probably used to copying and pasting text.  y/p probably isn&#8217;t much faster than ctrl+c ctrl+v other than the fact that you don&#8217;t have to stretch your fingers to do it.  Here are some improvements.</p>
<p><strong>yy</strong> &#8211; copy current line.  This is incredibly useful and fast when doing programming or any type of editing.  When using this command in conjunction with, &#8216;p&#8217; it will automatically add a line to make room.  For example you can go to the desired line, hit &#8216;yy&#8217; then &#8216;p&#8217; and it will copy the line paste it below and move your cursor to the newly created line.</p>
<h2>My most commonly used commands</h2>
<p>Like I have said earlier Vim has more shortcuts than you would ever even want to know about but here are the golden ones.  These are the commands that I use daily.</p>
<ul>
<li>&#8216;<strong>h,j,k,l</strong>&#8216; &#8211; The movement keys are essential</li>
<li>&#8216;<strong>w,b</strong>&#8216; &#8211; move forward &#8216;w&#8217; and backward &#8216;b&#8217; one whole word.</li>
<li>&#8216;<strong>dw</strong>&#8216; &#8211; delete a word</li>
<li>&#8216;<strong>u,ctrl+r</strong>&#8216; &#8211; Undo and Redo are a must</li>
<li>&#8216;<strong>dd</strong>&#8216; &#8211; This deletes the current line.  I am constantly using this.  It also puts the text into a buffer so you can put/paste it.</li>
<li>&#8216;<strong>0,$</strong>&#8216; &#8211; The &#8217;0&#8242; will put you at the beginning of the line and &#8216;$&#8217; will put you at the end.</li>
<li>&#8216;<strong>i,a</strong>&#8216; &#8211; The &#8216;i&#8217; will put you in insert mode at the cursor.  &#8216;a&#8217; will put you in insert mode after the cursor.  Think of it like append.</li>
<li>&#8216;<strong>:52</strong>&#8216; &#8211; This will put you at line 52.  When you have errors in your program on line X use this command.</li>
<li>&#8216;<strong>o,O</strong>&#8216; &#8211; The &#8216;o&#8217; will create a line below and put you in insert.  &#8216;O&#8217; does the opposite.  It creates a line above.  This doesn&#8217;t really seem all that useful because you can always hit the enter key if you are at the end of the line but you are not always in insert mode or at the end of the line when you decide to make another line.</li>
<li>&#8216;<strong>f,F</strong>&#8216; &#8211; This is one of my favorite commands.  &#8216;f&#8217; will search forward in the line for the next character you type and &#8216;F&#8217; will search backwards.</li>
</ul>
<p>For example, lets say you have the following line of code:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
print LOG &quot;StateProvinceCode: $StateProvinceCode\n&quot;;
</pre>
<p>You could hit the &#8216;<strong>f</strong>&#8216; key then the &#8216;<strong>\</strong>&#8216; key and the cursor would be positioned right near the &#8216;n&#8217; so I could change this to a tab character instead of a newline character.</p>
<p>This doesn&#8217;t mean it will keep on searching, there is a different key for that.</p>
<p>&#8216;<strong>/</strong>&#8216; &#8211; Search.  This is the key to initiate a search.  You can use regular expressions or do a simple word search.</p>
<h2>Special commands for programmers</h2>
<p>Syntax highlighting &#8212; If for some reason Vim isn&#8217;t highlighting code by default you can turn it on by typing, &#8216;<strong>:syntax on</strong>&#8216; or add it to your .vimrc config file.<br />
&#8216;<strong>=%</strong>&#8216; &#8211; Will auto tab nested ifs/loops/functions.  Although Vim automatically tabs everything out for you, sometimes you will run into old code or poorly tabbed code where you want to fix it up real quick.  Just go to the first &#8216;{&#8216; in the code and hit this command and everything will be auto tabbed.<br />
&#8216;<strong>gd</strong>&#8216; &#8211; Jump to variable definition.  The g stands for go.  There are multiple ways you can use &#8216;<strong>g</strong>&#8216;, &#8216;<strong>gg</strong>&#8216; will go to the beginning of the file and &#8216;G&#8217; will go to the end.  In this case we are using &#8216;gd&#8217; to go to the variable definition.  For example, lets say you are about a mile down your code and you have a function that calls the variable, $someOldVariable.  To find out what is inside this variable or where it was first created you would move your cursor to that variable and hit, &#8216;gd&#8217; this would auto-magically move you to where that variable was first seen, AKA the variable definition.<br />
&#8216;<strong>%</strong>&#8216; &#8211;  Go to matching  () [] {}.  Sometimes you will have a very long loop and a bunch of nested functions.  If your tabbing isn&#8217;t the best it is sometimes tricky to find out which bracket belongs to which function.  The &#8216;<strong>%</strong>&#8216; will move your cursor to the start or end of the matching bracket.<br />
&#8216;<strong>&gt;&gt; and &gt;</strong>&#8216; &#8211; The double arrow, &#8216;<strong>&gt;&gt;</strong>&#8216; will shift the current line over one tab.  If you highlight a region of text you can shift the entire text over with &#8216;<strong>&gt;</strong>&#8216;.</p>
<h2>Conclusion</h2>
<p>Although there are literally hundreds of shortcuts and commands for Vim you will be far ahead of the regular text editor with just these few.  If you simply learned the commands in this article alone you would program/edit much faster and be more productive.</p>
<p>Remember: learn just the basics first.  Open a text file or project source file and move around and learn how to save it.  Learn how to undo-redo and basic editing in insert modes.  To really get the hang of Vim you will need to spend about 5 hours messing around in the editor. </p>
<p><a name="markbio"></a></p>
<div class="update">
<h3>About Mark Sanborn</h3>
<p><img style="float: right; margin: 0 0 8px 8px" src="http://eriwen.com/images/MarkSanborn.jpg"/></p>
<p>Hi, I am Mark Sanborn.  I am 22 and just graduated from the University of Montana.  I have had an interest in computers for as long as I can remember.  I still remember the DOS days and really started getting into computers when Windows 3.1 was around.  I made my first webpage in the 7th grade.  My passion for web design and computers has only progressed from there.</p>
<p><strong>How did I learn to program?</strong><br/>In college I was approached by a group that wanted a realty website created for the University business plan competition. I gladly took the job and forced myself to learn PHP/MySQL while working on the project.  By the time the project was complete I was fairly fluent in PHP and was confident I could build pretty much anything I set my mind to.  I later used these skills to create a corporate website with a custom e-commerce shopping cart for a client.</p>
<p><strong>Computer Related Education</strong><br/>I just received my B.S. in Business Administration Information Systems.  I scored nearly a perfect score on the MCP test allowing me to achieve the Microsoft Certifed Professional status.  While attending college I worked for the University as tech support for dorm students and faculty.  I have a lot of experience working with computers but there is still a lot I can learn from others.  I also believe that you learn the most by teaching it to others.  This is why I created my own blog.</p>
<p><strong>What Languages Do You Use?</strong><br/>HTML, CSS, MySQL, PHP, Java, XML, Bash. For some reason I want to learn python yet I don&#8217;t know what I would use it for. Some experience in: ASP, Visual Basic, ColdFusion.</p>
<p><strong>What Do You Do In Your Spare Time?</strong><br/>I spend a lot of time in front of the computer but I am not your typical programmer that loves Star Trek and converses with their friends about what to do in the event of zombie attacks.  All stereotypes aside, I love to play guitar I am interested in all types of music, mostly blues and classic rock.  I am an avid weight lifter and practice Judo.  I don&#8217;t consider myself a fan of team based sports; however, I love individual sports. Last summer I learned to paraglide and for the past two winters I have  been enjoying the fabulous sport of kiteboarding on snow.</p>
</div>


<p>Related posts:<ol><li><a href='http://eriwen.com/tools/awk-is-a-beautiful-tool/' rel='bookmark' title='awk is a beautiful tool'>awk is a beautiful tool</a></li>
<li><a href='http://eriwen.com/tools/grep-is-a-beautiful-tool/' rel='bookmark' title='grep is a beautiful tool'>grep is a beautiful tool</a></li>
<li><a href='http://eriwen.com/productivity/find-is-a-beautiful-tool/' rel='bookmark' title='Find is a beautiful tool'>Find is a beautiful tool</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/vim-is-a-beautiful-tool/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>awk is a beautiful tool</title>
		<link>http://eriwen.com/tools/awk-is-a-beautiful-tool/</link>
		<comments>http://eriwen.com/tools/awk-is-a-beautiful-tool/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 15:00:44 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=183</guid>
		<description><![CDATA[AWK is a very powerful programming language that we can use on the command-line for advanced text processing. I'd like to provide a guide so you can get started using it. I'll be covering the basics of AWK (named after Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan) and provide some useful examples. 

<h2>Tutorial</h2>

To best introduce <em>awk</em> I'd like to start with a practical example. Most of the applications for awk that I've dealt with involve formatting some output or data into something cleaner and more usable. This is certainly not the limit of awk, it is <strong>a full fledged language</strong> with all the power and responsibility to go with it.

Awk operates on one &#34;record&#34; at a time, which is each line by default. <strong>Each &#34;field&#34; in a record is separated by a space</strong> (by default) or another defined separator (using the -F option).
 <a href="http://eriwen.com/tools/awk-is-a-beautiful-tool/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/tools/grep-is-a-beautiful-tool/' rel='bookmark' title='grep is a beautiful tool'>grep is a beautiful tool</a></li>
<li><a href='http://eriwen.com/productivity/find-is-a-beautiful-tool/' rel='bookmark' title='Find is a beautiful tool'>Find is a beautiful tool</a></li>
<li><a href='http://eriwen.com/tools/vim-is-a-beautiful-tool/' rel='bookmark' title='Vim is a beautiful tool'>Vim is a beautiful tool</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>AWK is a very powerful programming language that we can use on the command-line for advanced text processing. I&#8217;d like to provide a guide so you can get started using it. I&#8217;ll be covering the basics of AWK (named after Alfred <strong>A</strong>ho, Peter <strong>W</strong>einberger, and Brian <strong>K</strong>ernighan) and provide some useful examples. </p>
<h2>Tutorial</h2>
<p>To best introduce <em>awk</em> I&#8217;d like to start with a practical example. Most of the applications for awk that I&#8217;ve dealt with involve formatting some output or data into something cleaner and more usable. This is certainly not the limit of awk, it is <strong>a full fledged language</strong> with all the power and responsibility to go with it.</p>
<p>Awk operates on one &#8220;record&#8221; at a time, which is each line by default. <strong>Each &#8220;field&#8221; in a record is separated by a space</strong> (by default) or another defined separator (using the -F option).</p>
<p>We&#8217;re going to print the file names, line-numbers, and function names of all duplicate functions so they&#8217;re super easy to find and remove. Suppose we have some output from grep with file names and line numbers using a command like this (pulled from my <a href="http://eriwen.com/tools/grep-is-a-beautiful-tool/">grep tutorial</a>):</p>
<pre class="brush: bash; light: true; title: ; notranslate">
# Prints javascript functions like this - &lt;file&gt;:&lt;line-num&gt;:&lt;line-content&gt;
grep -EnH &quot;^\s*function \w+&quot; *.js | sort
</pre>
<p>That&#8217;s all good and well, but this doesn&#8217;t quite give us what we want in a clear manner, it prints all functions and information in a kinda cludgy fashion. We can clean this up with a bit of awk. First let&#8217;s learn a basic awk command:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
awk '/'^$'/ { print &quot;blank line&quot; }' myfile
</pre>
<p>This snippet will print &#8220;blank line&#8221; for line that matches the regex: ^$ (a blank line). The pattern (between the two slashes, inclusive) is optional and we&#8217;ll see in the next example:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
awk 'BEGIN { print &quot;Hello, awk!&quot; } { print $2, $1 } END { print &quot;Goodbye, awk!&quot;}' myfile
</pre>
<p>How this reads is: Before processing (BEGIN), print &quot;Hello, awk!&quot; and then <em>print</em> the second field ($2) and then the first ($1) for each line of myfile, then after processing (END) print &quot;Goodbye, awk!&quot;. The BEGIN and END clauses are optional. </p>
<p>As explained above, a field is a sequence of non-whitespace characters. So if a line contained &quot;foo bar other stuff&quot;, awk would print &quot;bar foo&quot;. </p>
<p>One more thing before continuing: awk scripts can get ugly so it is useful to know you can read a file for awk commands:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
#My awk file: foo.awk
BEGIN { print &quot;Hello, awk!&quot; }
{
    print $2, $1
    # This is an awk comment
}
END { print &quot;Goodbye, awk!&quot; }

#Invoke foo.awk
awk -f foo.awk myfile
</pre>
<p>OK, let&#8217;s add some power to that old grep command. We can use the <em>-F</em> option to specify our delimiter so let&#8217;s add to our grep command like so:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
grep -Eoni &quot;^\s*function \w+&quot; *.js | awk -F ':' '{print $3,&quot; &quot;,$1,$2}' | sort
</pre>
<p>Now we have a sorted list of function names followed by their filename and line number by spaces. We needed to print $3 first so that we could easily sort by the function name and look for duplicates, but we&#8217;re not going to do that manually&#8230; oh noooooo way. </p>
<p>Let&#8217;s make it a bit prettier and <em>uniq</em>-ify our list of functions by function:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
# New part of our command
awk '{print $3,&quot;line&quot;,$4,$2}' | uniq -f 3 -D

# Full command
grep -Eoni &quot;^\s*function \w+&quot; *.js | awk -F ':' '{print $3,&quot; &quot;,$1,$2}' | sort | awk '{print $3,&quot;line&quot;,$4,$2}' | uniq -f 3 -D
</pre>
<p>Here we pipe our last command back into <em>awk</em> printing &lt;filename&gt; line &lt;line-num&gt; &lt;function-name&gt; and then use uniq on the 3rd field (-f 3) showing only the duplicates (-D). </p>
<h2>Other awk examples</h2>
<pre class="brush: bash; light: true; title: ; notranslate">
#Backup all JavaScript files with a .bak extension -- replace 'bash' with your shell
 ls *.js | awk '{print &quot;cp &quot;$0&quot; &quot;$0&quot;.bak&quot;}' | bash

#Print the number of lines that contain &quot;function&quot;
awk '/'function'/ {i = i + 1} END {print i}' myfile.js
</pre>
<h2>Conclusion</h2>
<p>AWK is admittedly a ten ton gorilla of a tool, so there is no way I could cover everything that it can do in one post. If there is enough demand I can write about some of the more advanced features like conditionals, variables, and formatting. <a href="http://eriwen.com/feed/" title="Subscribe to Eric's Blog">Stay tuned</a>!</p>
<h2>Further Reading</h2>
<p>To see how far this rabbit hole goes, you should check out a couple of my favorite references:</p>
<ul>
<li><a href="http://www.catonmat.net/blog/awk-nawk-and-gawk-cheat-sheet/">awk, nawk, and gawk cheat sheet</a></li>
<li><a href="http://en.wikipedia.org/wiki/Awk" title="AWK wikipedia entry">AWK &#8211; Wikipedia</a></li>
<li><a href="http://sparky.rice.edu/~hartigan/awk.html">Hartigan&#8217;s AWK reference</a></li>
</ul>
<p>Hope you found this informative and want to know more. I know you all probably have some awk gems to share, let&#8217;s see them!</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/tools/grep-is-a-beautiful-tool/' rel='bookmark' title='grep is a beautiful tool'>grep is a beautiful tool</a></li>
<li><a href='http://eriwen.com/productivity/find-is-a-beautiful-tool/' rel='bookmark' title='Find is a beautiful tool'>Find is a beautiful tool</a></li>
<li><a href='http://eriwen.com/tools/vim-is-a-beautiful-tool/' rel='bookmark' title='Vim is a beautiful tool'>Vim is a beautiful tool</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/awk-is-a-beautiful-tool/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Get sed savvy &#8211; part 3</title>
		<link>http://eriwen.com/tools/get-sed-savvy-3/</link>
		<comments>http://eriwen.com/tools/get-sed-savvy-3/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 11:30:57 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=68</guid>
		<description><![CDATA[We will learn about the <em>sed</em> delete (d), read (r) and write (w) commands today to round out your sed toolbox. Obviously, I won't be covering everything about sed. I literally have a book on <em>sed</em> that I keep handy because there is so much to it. The major parts I am covering should help you through 99% of the cases where sed is your best option. 

Soon we'll be looking at awk and other tools to continue the quest for command-line fluency. If you haven't already, install <a href="http://cygwin.com" title="Cygnus + Windows">Cygwin</a> and check out <a href="http://eriwen.com/tools/get-sed-savvy-1/">part 1</a> and <a href="http://eriwen.com/tools/get-sed-savvy-2/">part 2</a>.

<h2>Tutorial</h2>

One of the best ways to crank out code quickly is by using templates. Using the Stream EDitor, you can streamline the use of templates.
 <a href="http://eriwen.com/tools/get-sed-savvy-3/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/tools/get-sed-savvy-2/' rel='bookmark' title='Get sed savvy &#8211; part 2'>Get sed savvy &#8211; part 2</a></li>
<li><a href='http://eriwen.com/tools/get-sed-savvy-1/' rel='bookmark' title='Get sed savvy &#8211; part 1'>Get sed savvy &#8211; part 1</a></li>
<li><a href='http://eriwen.com/tools/awk-is-a-beautiful-tool/' rel='bookmark' title='awk is a beautiful tool'>awk is a beautiful tool</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>We will learn about the <em>sed</em> delete (d), read (r) and write (w) commands today to round out your sed toolbox. The major parts I am covering should help you through 99% of the cases where sed is your best option. </p>
<p><img src="http://eriwen.com/images/terminal.png" style="float: right; margin: 8px 0 8px 8px" /> Soon we&#8217;ll be looking at awk and other tools to continue the quest for command-line fluency. If you haven&#8217;t already, install <a href="http://cygwin.com" title="Cygnus + Windows">Cygwin</a> and check out <a href="http://eriwen.com/tools/get-sed-savvy-1/">part 1</a> and <a href="http://eriwen.com/tools/get-sed-savvy-2/">part 2</a>.</p>
<h2>Tutorial</h2>
<p>One of the best ways to crank out code quickly is by using templates. Using the Stream EDitor, you can streamline the use of templates.</p>
<p>Suppose we have a template <abbr title="HyperText Markup Language">HTML</abbr> file that we want to reuse often. Maybe it looks like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;template.html&lt;/title&gt;
     &lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;nav&quot;&gt;Navigation here&lt;/div&gt;
        &lt;div id=&quot;content&quot;&gt;
%%CONTENT%%
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now we want to replace <em>&quot;%%CONTENT%%&quot;</em> with the contents of an HTML Fragment file. The syntax is simple: &#8216;/&lt;pattern&gt;/r&#8217;:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
sed '/^%%CONTENT%%/r fragment.htmlf' template.html
</pre>
<p>The above script will append the contents of <em>fragment.htmlf</em> <strong>immediately after</strong> <em>&quot;%%CONTENT%%&quot;</em>. So we can use the delete command to fix that:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
sed -e '/^%%CONTENT%%/r fragment.htmlf' -e '/^%%CONTENT%%/d' template.html &gt; whole.html
</pre>
<p>This might seem slightly useless, but the power here is in the simplicity. Many times I&#8217;m generating bits of Wiki code or HTML, and this has been invaluable. </p>
<p>OK, now for one more command: <em>write (w)</em>. Suppose we have a <abbr title="Comma Separated Values">CSV</abbr> file that we want to split into several files depending on the value in the last cell. We could do this with <a href="http://eriwen.com/tools/grep-is-a-beautiful-tool/" title="grep tutorial">grep</a>, or awk (coming soon), but with sed we can do it with more efficiently:</p>
<pre class="brush: bash; light: true; title: ; notranslate">
#sedscript file
/,[0-9]+$/w numbers.csv
/,[A-Za-z]+/w letters.csv
/,[^A-Za-z0-9]+/w symbols.csv

sed -r -f sedscript original.csv
</pre>
<p>Now numbers.csv will contain all rows that the last cell containing numbers, and so on for letters.csv and symbols.csv. A neat application for this might be sorting your giant contacts list into different files based on some criteria. This is a simple example, but you can probably think of a more useful scenario where you&#8217;d want to filter and split a file. </p>
<h3>Other Examples</h3>
<pre class="brush: bash; title: ; notranslate">
#Print everything outside the &lt;html&gt; tag (check DOCTYPES)
sed '/&lt;html&gt;/,/&lt;/html&gt;/d' myfile.html

#Convert rn (DOS) to UNIX n
sed 's/$//' myfile        #Windows
sed 's/.$//' myfile       #Linux/UNIX
</pre>
<h2>Conclusion</h2>
<p>You have now learned several <em>sed</em> commands and patterns you can use to make editing files and some searching tasks much more efficient, and <strong>even better, scriptable</strong> so they can be automated in a process. One cool application would be to get comments from a set of files and post them to a wiki. It would sure make collaboration slick, right?</p>
<p>Obviously, you can bookmark this stuff but you&#8217;ll really get good at it only if you just try it out. Keep sharing your experiences and command lists, they&#8217;re great! </p>


<p>Related posts:<ol><li><a href='http://eriwen.com/tools/get-sed-savvy-2/' rel='bookmark' title='Get sed savvy &#8211; part 2'>Get sed savvy &#8211; part 2</a></li>
<li><a href='http://eriwen.com/tools/get-sed-savvy-1/' rel='bookmark' title='Get sed savvy &#8211; part 1'>Get sed savvy &#8211; part 1</a></li>
<li><a href='http://eriwen.com/tools/awk-is-a-beautiful-tool/' rel='bookmark' title='awk is a beautiful tool'>awk is a beautiful tool</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/get-sed-savvy-3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Get sed savvy &#8211; part 2</title>
		<link>http://eriwen.com/tools/get-sed-savvy-2/</link>
		<comments>http://eriwen.com/tools/get-sed-savvy-2/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 13:36:31 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=64</guid>
		<description><![CDATA[Now that you know a bit about the Stream EDitor from the <a href="http://eriwen.com/tools/get-sed-savvy-1/" title="SED tutorial">last sed tutorial</a>, we are going to expand our knowledge of substitution and line printing with an interesting scenario.

Suppose we want to let someone else know what kinds of functions are in a given Javascript file. Think of it as a simple sort of Javadoc for CSS or Javascript. The way we are going to do this is look at all of the files modified in the last day and then extract the comments out of them and put them somewhere (on a wiki perhaps?). <strong>Doing this kind of automation will increase team communication and productivity immensely if done correctly.</strong>

<h2>Tutorial</h2>

Download and install <a href="http://www.cygwin.com/" title="Cygnus + Windows">Cygwin</a> if you're on Windows to follow along. 

[code language="bash"]
# Single-line comments - grep is better but we can use sed
sed -n '///p' blah.js > /tmp/comments.out

# Multi-line comments
sed -n '//*/,/*//p' blah.js >> /tmp/comments.out
[/code] <a href="http://eriwen.com/tools/get-sed-savvy-2/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/tools/get-sed-savvy-3/' rel='bookmark' title='Get sed savvy &#8211; part 3'>Get sed savvy &#8211; part 3</a></li>
<li><a href='http://eriwen.com/tools/get-sed-savvy-1/' rel='bookmark' title='Get sed savvy &#8211; part 1'>Get sed savvy &#8211; part 1</a></li>
<li><a href='http://eriwen.com/tools/awk-is-a-beautiful-tool/' rel='bookmark' title='awk is a beautiful tool'>awk is a beautiful tool</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Now that you know a bit about the Stream EDitor from the <a href="http://eriwen.com/tools/get-sed-savvy-1/" title="SED tutorial">last sed tutorial</a>, we are going to expand our knowledge of substitution and line printing with an interesting scenario.</p>
<p>Suppose we want to let someone else know what kinds of functions are in a given Javascript file. Think of it as a simple sort of Javadoc for CSS or Javascript. The way we are going to do this is look at all of the files modified in the last day and then extract the comments out of them and put them somewhere (on a wiki perhaps?). <strong>Doing this kind of automation will increase team communication and productivity immensely if done correctly.</strong></p>
<h2>Tutorial</h2>
<p>Download and install <a href="http://www.cygwin.com/" title="Cygnus + Windows">Cygwin</a> if you&#8217;re on Windows to follow along. </p>
<pre class="brush: bash; light: true; title: ; notranslate">
# Single-line comments - grep's better but we can use sed
sed -n '///p' blah.js &gt; /tmp/comments.out

# Multi-line comments
sed -n '//*/,/*//p' blah.js &gt;&gt; /tmp/comments.out
</pre>
<p>Now, the <em>sed</em> commands above are tricky so here is how you can understand them: The <em>-n</em> option tells sed not to print anything unless you tell it specifically what to print. The comma [,] in between the two patterns tells sed to match everything between the two patterns, in this case everything between multi-line comments /* and */ and then the <strong><em>p</em>-command prints whole lines that match the pattern space</strong>.</p>
<p>We can combine these two commands to streamline a killer process.</p>
<pre class="brush: bash; light: true; title: ; notranslate">
# sed script file
////p
//*/,/*//p

# Use the sed script to print all comments
sed -n -f sedscr blah.js &gt; /tmp/comments.out
</pre>
<p>Now we have a nice little summary of our Javascript files we can post to a wiki or diff with another version to see what was added.  Note that the <em>sed</em> print command prints the whole line, so if you have comments at the end of a line you will get the beginning of that line also. Not a perfect solution, but something quick and easy!</p>
<h2>Other Examples</h2>
<pre class="brush: bash; light: true; title: ; notranslate">
# Print lines longer than 80 characters
sed -n '/^.{81}/p' myfile

# Delete blank lines
sed '/^$/d' myfile

# Substitution optimized for speed
sed '/Yahoo/ s//Not Microhoo/g' myfile
</pre>
<h2>Conclusion</h2>
<p>You should now be getting pretty proficient with <em>sed</em>. Use it along with <a href="http://eriwen.com/productivity/find-is-a-beautiful-tool/" title="find command-line tool">find</a> and <a href="http://eriwen.com/tools/grep-is-a-beautiful-tool/" title="grep command-line tool">grep</a> and you will find yourself feeling much more comfortable on the command-line. </p>
<p><strong>I encourage you to experiment a bit and use this even in circumstances where you know it&#8217;s not necessary</strong>, just to get the hang of it. In the long run you&#8217;ll end up increasing your productivity by using these most powerful tools.</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/tools/get-sed-savvy-3/' rel='bookmark' title='Get sed savvy &#8211; part 3'>Get sed savvy &#8211; part 3</a></li>
<li><a href='http://eriwen.com/tools/get-sed-savvy-1/' rel='bookmark' title='Get sed savvy &#8211; part 1'>Get sed savvy &#8211; part 1</a></li>
<li><a href='http://eriwen.com/tools/awk-is-a-beautiful-tool/' rel='bookmark' title='awk is a beautiful tool'>awk is a beautiful tool</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/tools/get-sed-savvy-2/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

