Awesome OS X Command Line

A curated list of shell commands and tools specific to OS X.

“You don’t have to know everything. You simply need to know where to find it when necessary.” (John Brunner)

Camel case transforms

/**
  * Credit: sidharthkuruvila
  * Source: http://ift.tt/29KXOcU
  * Takes a camel cased identifier name and returns an underscore separated
  * name
  *
  * Example:
  *     camelToUnderscores(“thisIsA1Test”) == “this_is_a_1_test”
  */

def camelToUnderscores(name: String) = “[A-Z\\d]”.r.replaceAllIn(name, {m =>
  “_” + m.group(0).toLowerCase()
})

/*
 * Takes an underscore separated identifier name and returns a camel cased one
 *
 * Example:
 *    underscoreToCamel(“this_is_a_1_test”) == “thisIsA1Test”
 */

def underscoreToCamel(name: String) = “_([a-z\\d])”.r.replaceAllIn(name, {m =>
  m.group(1).toUpperCase()
})

rsync IDE project files

The jury is still out on whether to version control the IDE files (see for example this question on StackOverflow). I recently tend to agree with Anton and lend towards not version-controlling or at least keeping them separate.

This little rsync script can help moving all project files to a separate hierarchy so that you can manage them separately from your source tree:

#!/bin/sh
rsync -av \
–filter=’+ */’ \
–filter=’+ .classpath’ \
–filter=’+ .project’ \
–filter=’+ **/*.iml’ \
–filter=’+ .idea/***’ \
–filter=’- *’ \
–prune-empty-dirs $1 $2

Thanks Shane Meyers for the insight into rsync filter patterns.