Made myself a nice new bash prompt using lua. Code can be found in this gist.

I started off trying to set PS1, but bash will incorrectly calcuate the prompt length. This leaves you with strange line wrapping behaviour. Thanks to Rob Hoelz I found out about PROMPT_COMMAND, which allows you to run a command before PS1 is printed.

I used ljsyscall to avoid as many new processes as possible, they could be replaced by commands if you want.

To get the git and mercurial (hg) status, I had to call out to see if the current directory is inside a repository: this can sometimes be slow, as git and hg have to traverse the whole way up the directory tree stat-ing for .git and .hg folders.

EDIT: Using PROMPT_COMMAND caused issues when scrolling through history, or pressing backspace at the beginning of a line. From the #bash IRC channel I found out that you can inform bash of non-printing characters by wrapping the bytes in \1 and \2. The gist has been updated.