My OSX Terminal Prompt (Reposted from Tumblr)


I wanted to post this on LosTechies, originally, but I didn’t have a good blogging tool at the time. I’m using MarsEdit now, and it seems to do what I want… but I digress…

My OSX Terminal Prompt

I made a few very minor tweaks to my OSX prompt after posting the previous screen shot on Tumblr. There’s not a lot of difference, here, but I also wanted to include the PS1 export in case others want to use it (by request of @rkitson)

My OSX Prompt

The first thing to note is that there is a blank line after the last command and before the current location / status indicators.

The first section, in white, is the current folder. I added a trailing / to this. Makes it easier to understand when your at the root folder or at ~/

The second section, in green, shows the current branch and status of a git repository. This is built into git, which is cool. No more parsing out git status messages. I haven’t quite figured out all of the symbols for this, but here’s the ones I do know:

  • “=” is for a tracking branch, and says current commit is same as remote
  • “>” is also for a tracking branch, and says current commit is forward of remote
  • “<” is also for a tracking branch, and says current commit is behind remote
  • “*” is for local changes that are not yet committed
  • “%” I don’t remember what this is for

The prompt combines these symbols in various ways. For example, “=*” says local changes not committed, but most recent commit is same as remote. This section hides itself when you’re not in a git repository.

The third section, in red, shows the RVM ruby version and gemset that is currently being used. This is built into RVM, as well. Just have to specify which options you want (and I don’t remember what the options mean off-hand). This section hides itself when you’re not using any specific version of ruby, with RVM.

Finally, I drop to a new line before putting “$ ” – yes, with a space – as my prompt. This keeps the prompt at the same place on the screen at all times.

… and not shown in this screen shot, I set the title bar of the terminal to “username@machinename”

The PS1 Settings For This Prompt

For those that are interested, here’s the PS1 setting for this:

function prompt {

local LIGHT_RED=”[33[1;31m]”
local LIGHT_GREEN=”[33[1;32m]”
local NO_COLOUR=”[33[0m]”

local TITLEBAR=’[33]0;u@h07]’

source ~/.git-completion.bash

export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWUPSTREAM=auto
export GIT_PS1_SHOWSTASHSTATE=true

PS1=”$TITLEBARnw/$LIGHT_GREEN$(__git_ps1 ‘ (%s)’) $LIGHT_RED$(~/.rvm/bin/rvm-prompt i v g)n$NO_COLOUR$ “

}

#call the prompt function to set things in motion
prompt

Evaluating Alternatives vs Reacting To Differences