Multiple Email Addresses with a Default in Git

Someone pointed out to me that my commits to github were showing up using my work email address (and therefore my commits weren’t connected to the proper account). I do personal and professional work on the same laptop and I find myself wanting to commit one git repo via one email address and one repo to another.

The first idea I had was to set the global email address to the default and then set individual email addresses on a per-project basis. Git always uses the global email address if one’s set. Thanks, git. Anyway, I have a super-hacky workaround for this based partially on my PS1 code for my bash profile. The first thing you have to do is open your ~/.gitconfig file and remove the line. This was originally set using git config --global, but we’ll be handling this more manually:

	gb=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
	if [[ -z $gb ]]
	then echo -e ""
		ge=$(git config
		if [[ -z $ge ]]
			git config ""
			echo -e ""$gb'\n\r'
		else echo -e $ge":"$gb'\n\r'

This first line takes the output from git branch and finds a line with a * in it indicating that branch is selected. If it finds one, it re-searches for the name specifically. If either of these is not found, an empty string is returned.

in bash, [[ -z ]] indicates empty. If we find that the output of the branch script is empty, we stop checking. Otherwise, we set the local email address to the default.

Finally, we output the various bits for use in our PS1 shell prompt, but you don’t have to do that if you don’t want to.

The final output looks something like this (only more colorful)

which is now how I like to set up my bash environment.

PHP, Python, GoLang, and Node.js all served by Apache port 80

I dabble in node.js, php, python, and more. Often, these services will produce webservers, and I’d like to try them out in my browser. I also would like to be able to test redirects for things like oauth. In order to get a proper passback from somewhere like Facebook, I need to simulate a full website url without port. It also would be nice to do this without having to shut down one, adjust settings, and restart the other.

The concept:
/etc/hosts or Windows/system32/drivers/hosts will handle incoming request handling to a url

  • Apache handles all requests from port 80
  • Apache uses VirtualHosts to redirect traffic from port 80 to various ports
  • Node/Python/Go/Etc. Will handle requests from specific ports.

An example:

This tells your computer that every program that requests data from should be forwarded to your computer. This is true for all protocols, http, https, ftp, etc.


<VirtualHost *:80>
    ProxyPass / retry=0

We’ve told apache to create a VirtualHost on port 80. The servername matches the entry in /etc/hosts. The proxypass indicates to where we should forward this request, in this case, to local port 3000. retry=0 tells apache not to cache the results and to always try to serve the page (even if node was down last time)


https.createServer(options, function (req, res) {
  res.end("hello world\n");

This is a basic node server using port 3000. If we receive a request to we should see it handled by node.

Similar servers can be set up in Python, GoLang, etc. And as long as they don’t steal port 80 from Apache, they can handle requests as normal. I’ve found this very useful.

My Shell and Bash Prompt Configuration

I use Bash every day in my work and at home on projects and I find the default setup of the system to be cumbersome. Call me a geezer, but I missed my dos-style information on the command line. I’ve replicated some of that in the following way:

This is in my ~/.profile file
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/|\1/'

This code provides a pwd in green and then a simple > character to indicate where your command line begins. This is easy enough to customize — replace the > with a $ if you like that, or change the color with something other than 0;32m.
Then, it creates a pipe and the current git branch (if available)


ssh_askpass missing on osx

I recently installed tower on my system and tried to connect to a git repo I use. I don’t have my default password set in git (I like typing passwords), so when it tried to prompt me, I didn’t have a means of telling Tower what my password was. This is an oversight in OSX, but hey, we can fix that. This is the error I received
ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory
Permission denied, please try again.

And here’s the language to fix it. Place this code into a file at /usr/libexec/ssh-askpass and make it executable chmod +x /usr/libexec/ssh-askpass and you should be good to go. Tower will prompt you for passwords using a handy dialog.

#! /bin/sh

# An SSH_ASKPASS command for MacOS X
# Author: Joseph Mocker, Sun Microsystems

# To use this script:
# setenv SSH_ASKPASS "macos-askpass"
# setenv DISPLAY ":0"


DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""
DIALOG="$DIALOG with icon caution with hidden answer"

result=`osascript -e 'tell application "Finder"' -e "activate" -e "$DIALOG" -e 'end tell'`

if [ "$result" = "" ]; then
exit 1
echo "$result" | sed -e 's/^text returned://' -e 's/, button returned:.*$//'
exit 0

Add PWD to Bash Default

I grew up with DOS, so call me a throwback user, but when I open Bash on my Mac, I’d really like to know where the heck I am. By default, the prompt shows your computer’s name, then the name of the directory you’re in. This works fine if you never have duplicate directory names, but when I’m doing dev work, I often have multiple windows open for staging/prod/dev work, and they all have the same name as they’re supposed to. This script goes into your ~/.profile file and will change bash to show something like


Here’s the code you put into your ~/.profile file (create one if you need to):