Refactored login stuff.

See http://blog.flowblok.id.au/2013-02/shell-startup-scripts.html