Skip to content

A shell script to make your prompt pretty. Works with bash and zsh, with git.

Notifications You must be signed in to change notification settings

dotcode/multi-shell-git-prompt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

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)

About

A shell script to make your prompt pretty. Works with bash and zsh, with git.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages