blogging about startups, programming, and technology.

Install .dmg Apps on Mac through Terminal or a Bash Script

Recently, I've been taking advantage of Apple's 14-day Return Policy on Macbooks to try out different models. In order to avoid losing valuable time reinstalling and configuring the machines, I've started automating setup of my entire environment.

For the most part I did this by writing scripts to install brew packages, gems, and npm modules. However, I found that I'd go to open a package and found that I had forgotten to go to the website, install it, configure it, etc.

I knew I needed a way to 1) track the applications that I use 2) Automatically install them when I start developing on a new machine. As a side bonus, I wanted to unmount and remove the .dmg file after installation.

I've written several bash scripts to congiure my machine. Here's the script to install a .dmg file. This example uses pgAdmin3 which I use for Postgresql / Rails development.

#!/usr/bin/env bash
    # Install pgAdmin3 using bash
    # Ask for the administrator password upfront.
    sudo -v
    # Keep-alive: update existing `sudo` time stamp until the script has finished.
    while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
    # Download - note wget must be installed (I install through brew)
    wget -O ~/Desktop/pgadmin3-1.20.0.dmg
    # Mount and install
    hdiutil mount ~/Desktop/pgadmin3-1.20.0.dmg
    sudo cp -R "/Volumes/pgAdmin3/" /Applications
    # Cleanup - unmount and remove source file
    hdiutil unmount "/Volumes/pgAdmin3/"
    rm ~/Desktop/pgadmin3-1.20.0.dmg
    # Verify it's installed correctly
    ls -la /Applications | grep ''
    echo "Done. Ensure that is in the /Applications folder!"  

The source is available on my GitHub:

Check out the dotfiles repo for other automation / recipes!

Git Interactive Rebase Tutorial

Incremental git

Git commits should be a reflection of incremental changes.

Think of a commit as snippet of code that might, at some point, need to be
cherry-picked or reverted independently of other commits.


Cherry-picking allows you to apply a particular commit to your branch. It's
awesome for applying commits to a detached branch, applying hotfixes, etc. We
can do hotfixes by fixing master and then cherry-picking the commit to grab
the code that fixes it and applying it to a detached hotfix branch. This allows
us to "work off of master" and only detach for hotfixes. It also ensures that
the same commit hashes used for the hotfix are merged into master.

git cherry-pick <hash>  


Like cherry-picking, you can revert hashes. This is critically important for
reverting state of the master branch for hotfixes. If we can ID a commit that's
breaking a feature or causes a significant bug by it's hash, we can revert
that particular hash instead of the entire branch.

git revert <hash>  

Interactive Rebasing

When you're doing git, you can do

git rebase -i master  

for an interactive rebase!

Code test

This is a test of code

var s = "JavaScript syntax highlighting";  
    $scope.whatever = function() {
    Events.all(function(data) {  
        $ =;
$test = 12345;
.test {
      margin-left: 10px;
    code {  
        white-space: pre-wrap;       /* CSS 3 */
        white-space: -moz-pre-wrap;  /* Mozilla */
        white-space: -pre-wrap;      /* Opera 4-6 */
        white-space: -o-pre-wrap;    /* Opera 7 */
        word-wrap: break-word;       /* IE 5.5+ */