This is a considerably faster, but much more basic alternative to bash-git-prompt.
When adding this script to your .bash_profile
or .bashrc
, it'll display the selected branch of the current folder (if it's a git repo), and whether it's modified (yellow) or contains staged files (cyan).
The script makes the assumption, that a .git
folder only exists when the directory is a git repo. Also, it checks for the english version of the git status
command, so if you're using git in a different locale, make sure to adjust this.
You always need to call
git --porcelain
or something like that to get the status information. So the only way to make it fast it to callgit
only once, and make sure that processing is as fast as possible.I have written a very fast git-status in C++ with maximum optimizations. It even has a
--refresh-sec
parametr which will avoid extra calls togit
if previous call was less than--refresh-sec
seconds ago. I think this is the fastest possible way to do this.It is for zsh, but you can adapt it to bash. And it is very fast: https://gitlab.com/cosurgi/zsh-git-cal-status-cpp
Posting entire solution would involve parsing the output of
git status --porcelain --branch --git-dir ARG1 --work-tree ARG2
. That's what this program does. Doing it in bash or any other interpreted language wouldn't be as fast.