Add following to your .bashrc
:
__git_ps1() { setsid -w /bin/bash -c 'sleep 1 & . /usr/lib/git-core/git-sh-prompt && __git_ps1 "$@" & wait -n; p=$(/usr/bin/ps --no-headers -opgrp $$) && [ $$ = ${p:-x} ] && /usr/bin/kill -9 0; echo "PGRP mismatch $$ $p" >&2' bash "$@"; }
1s usually is enough for local files which are in cache on modern machines, but does not delays the shell prompt too much in case network share need a bit longer.
Note: Due to timeout
killing git
this may leave .lock
-files in your .git
directory, which is a bit annoying, as git
bails out if it sees such .lock
when altering a .git
repo. However git
tells the lockfile positions and you then can(must) manually rm
them. You can improve this by setting GIT_PS1_xxxx variables such, that git
needs no locking when evaluating the $PS1
. However I am not completely sure which options causes this issue or not. YMMV.