Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# version __git_ps1 that won't invoke any git commands, but might be a little disk intensive in deep repositories
function __git_ps1() {
local P="";
until [[ `readlink -f "$P"` = "/" ]]; do
if [[ -d "$P.git/" ]]; then
P="$P.git/";
local B=`cat ${P}HEAD | sed -re 's/.+\///g'`;
if [[ -d "${P}rebase-merge/" ]]; then
if [[ -f "${P}rebase-merge/interactive" ]]; then
B="$B|MERGING-i";
else
B="$B|MERGING-m";
fi
else
if [ -d "${P}rebase-apply" ]; then
if [ -f "${P}rebase-apply/rebasing" ]; then
B="$B|REBASE"
elif [ -f "${P}rebase-apply/applying" ]; then
B="$B|AM"
else
B="$B|AM/REBASE"
fi
elif [ -f "${P}MERGE_HEAD" ]; then
B="$B|MERGING"
elif [ -f "${P}CHERRY_PICK_HEAD" ]; then
B="$B|CHERRY-PICKING"
elif [ -f "${P}REVERT_HEAD" ]; then
B="$B|REVERTING"
elif [ -f "${P}BISECT_LOG" ]; then
B="$B|BISECTING"
fi
fi
printf "$1" $B;
P="/";
else
P="$P../";
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment