Normalizing Line Endings Across Multiple Files

Terminal Recently I’ve been noticing some of my C# files have inconsistent line endings.

Visual Studio: Inconsistent Line Endings

The Problem

The line endings in the following file are not consistent. Do you want to normalize the line endings?

This probably means some of the developers have been editing our source code using a text-editor (instead of Visual Studio) and they had their line endings set to “Unix” or “Mac” instead of “Dos/Windows”. This isn’t a big deal, though it is annoying.

Vim: Convert All Files to Dos/Windows Line Endings

Since I don’t know which files have this problem, I decided to just normalize all the line endings. There are various ways to do this, but I chose to use vim since the documentation on this topic is excellent.

To convert from any mixture of CRLF endings and LF-only endings, to CRLF endings:

:set ffs=dos
:args **\*.cs
:argdo w

We’re basically asking vim to assume Dos/Windows line endings, having it open all *.cs files (C# code files), then having it write the line-ending changes.

Downsides

This does change every single file that was found, regardless of the original line endings. It’s best to do this as one commit in source control to avoid any confusion.

Alternatives

You can also use unix2dos to do this conversion or any scripting language (python, perl, powershell).

Some people also let their source control handle their line endings. Git can enforce these line endings by updating them for you if you prefer. However, at my office, we choose not to let our source control alter our code in any way; we prefer to do that ourselves. :)

Now get back to coding!

How to Install Specific Android SDK Packages from Command Line (headless server)

DroidInstalling the Android SDK on a headless server doesn’t seem to be very well documented. I recently needed to do this to get the SDK installed on a TeamCity build agent to automate Android builds and tests.

Below are some simple instructions to help you along the way. I’m using a Mac, so you may need to use slightly different commands if you’re using Linux.

Continue reading

OS X Lion Will Debut on the Mac App Store Tomorrow!

Mac OS X LionWhat a day for Apple and their fans!  First the Google+ app hits the iPhone app store, then Apple announces record-breaking sales during Q3 2011, and then during this announcement CFO Peter Oppenheimer says that OS X Lion will hit the Mac App Store July 20th for $29.99!  And if that isn’t ringing clear enough, that’s TOMORROW!  The latest release will include 250 new features, including plenty of changes to make it look and feel more like iOS.  If this all sounds good, you can visit the Mac OS X homepage to learn more about Lion or check out the hands-on preview over at Engadget.

Mac OS X Lion