Refactor common shell functions out.