Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A shell script to make your prompt pretty. Works with bash and zsh, with git.
branch: master

This branch is 5 commits ahead of dotcode:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README.md
prompt.sh

README.md

Multi-shell git prompt

This is a shell script that provides useful information (in your prompt) about the repository that you are in. It currently works for Git, under zsh as well as bash. It's a trimmed down version of the multi-shell-repo-prompt, with the Mercurial stuff removed.

It's been written to make it easy to tweak the colours and the characters used, so you can get it setup to dislay how you want without having to dirty your hands with too much of that filthy shell code that's like … so from the 1970's. The aim when tweaking this was to (as far as possible) have one block of code that could be dropped into a bash or zsh initialisation file and "just work".

I frequently switch between bash and zsh, and like my prompts to contain the same functionality - only differing in a couple of respects (it's nice if the prompt provides some visual indication of what shell you're under). To this end the default colours are slightly different, and outside of a repo the prompt character differs between bash and zsh - under bash it's '$', under zsh it's '%'. Trivially easy to change this to something you're happier with.

As well as the usual stuff you might like in your prompt, it displays which part of your current working directory is tracked in version control. At the end of the prompt it displays the name of the branch you are currently on, as well as the status of the repo - how many files you have modified or untracked or wha'eva.

This is entirely based on Steve Losh's excellent work, both his "extravagant zsh prompt" (note his zsh prompt is more sophisticated than this one detailed here) - and hg-prompt as well.

The infinitely talented Andrew Hayward(@arhayward) wrote most of the code, I just fixed a few bugs (doubtlessly introducing a few of my own) and made it work in zsh as well as bash (I've tried to use as much shell-agnostic code as possible - although there's probably quite a bit of it that is non POSIX-compliant - would be nice to see it forked and working in other shells as well!)

Oh, and - like 90% of projects on teh internets - I also received a bit of help from Matthew Somerville(@dracos) as well.

How does it look

Under bash, when in a dirty git repo:

bash git dirty

Under zsh, when in a clean git repo:

zsh hg clean

Requirements

If you want to make your OS X prompt as pretty as shown, have a read of Candy Colored Terminal, also by Steve Losh.

Installation

Fork the repo then link to prompt.sh from within your ~/.bash_profile or ~/.zshrc or wha'eva (note that you should remove any pre-existing lines in those files that start with export PS1= (in bash) or PROMPT= (in zsh)):

[… usual stuff contained in .bash_profile or .zshrc or wha'eva …]

. ~/Dropbox/home/prompt.sh

[… usual stuff contained in .bash_profile or .zshrc or wha'eva …]

Note that I keep prompt.sh in Dropbox - not necessary to get this working (obviously), but I like to keep all my user shell intialisation files (.bash_profile/.zshrc/.gitconfig/.inputrc/.hgrc etc etc etc) in Dropbox - then symlink to them (I like the same prompt and history and shell behaviour on all my machines). It aids in the setup of new machines, and helps if they get stolen (which mine do).

If you like this idea, but don't know how to create a symlink, then RTFM^H^H^H^H have a look at this example …

$ cd
$ mv .bash_history ~/Dropbox/home/ # move your bash_history to dropbox
$ ln -s ~/Dropbox/home/.bash_history .bash_history # create a symlink to your .bash_history 

Author

Andrew Hayward & Jude Robinson (dotcode at gmail dot com @dotcode)

Something went wrong with that request. Please try again.