I’ve been using this excellent hack for a while to get the current git branch in my shell prompt.
That takes care of knowing what branch you’re on, but I still found myself running
git status often after
cd:ing into a working directory, to find out if it was dirty (had uncommitted stuff). If it is, I want to handle that before starting on something else.
I hacked that in, and now my prompt looks like e.g.
when the working directory is clean, and
when it’s dirty – an asterisk is added.
Code for bash, goes into
I have nearly no experience in shell scripting, so please let me know how this can be improved. For one thing, I expect it could be made more efficient by just running
git status once and getting both branch and dirtiness from that.
Feel free to contribute versions for other shells.