Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Version control aware ps1
. /etc/bash_completion.d/git
function customW {
echo $PWD | sed 's|.*/\([a-Z0-9][a-Z0-9]*/[a-Z0-9][a-Z0-9]*\)|\1|'
}
function hasToPush {
git diff-index --quiet --cached HEAD &>/dev/null &&
(git svn dcommit --dry-run 2>/dev/null | grep -q "diff-tree" && echo "")
}
function hasToPull {
git diff-index --quiet --cached HEAD &>/dev/null && (
latest=$(git svn log | awk 'NR==2' | cut -d ' ' -f1 | tr -d 'r')
current=$1
(($latest > $current)) && echo ""
)
}
function discoverScmInfo {
gitPs1=$(__git_ps1)
if [ "x$gitPs1" != "x" ]; then
gitsvn=$(git svn info 2> /dev/null | grep Revision)
gitsvn=${gitsvn#Revision: }
if [ "x$gitsvn" != "x" ]; then
echo "${gitPs1}($gitsvn$(hasToPull $gitsvn)$(hasToPush))"
else
echo "$gitPs1"
fi
fi
}
PS1='$(customW)$(discoverScmInfo)\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.