Created
February 2, 2014 19:50
-
-
Save beckje01/8773774 to your computer and use it in GitHub Desktop.
Bash Prompt adapted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c_cyan=`tput setaf 6` | |
c_red=`tput setaf 1` | |
c_green=`tput setaf 2` | |
c_sgr0=`tput sgr0` | |
parse_git_branch () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
git_status="$(git status 2> /dev/null)" | |
branch_pattern="^#?.*On branch ([^${IFS}]*)" | |
remote_pattern="Your branch is (.*) of" | |
diverge_pattern="Your branch and (.*) have diverged" | |
# add an else if or two here if you want to get more specific | |
if [[ ${git_status} =~ ${remote_pattern} ]]; then | |
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then | |
remote="^" | |
elif [ ${BASH_REMATCH[1]} == "behind" ]]; then | |
remote="V" | |
fi | |
fi | |
if [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="↕" | |
fi | |
if [[ ${git_status} =~ ${branch_pattern} ]]; then | |
branch=${BASH_REMATCH[1]} | |
echo "${branch}${remote}" | |
fi | |
else | |
return 0 | |
fi | |
} | |
branch_color () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
git_status="$(git status 2> /dev/null)" | |
color="" | |
if [[ ${git_status} =~ "working directory clean" ]]; then | |
color="${c_green}" | |
else | |
color=${c_red} | |
fi | |
else | |
return 0 | |
fi | |
echo -ne $color | |
} | |
head_sha () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1; then | |
echo "$(git rev-parse --verify HEAD)" | cut -c -7 | |
else | |
return 0 | |
fi | |
} | |
export PS1='$(if git rev-parse --git-dir >/dev/null 2>&1; then \ | |
echo "$(branch_color)$(parse_git_branch)\[${c_sgr0}\] \W $ "; \ | |
else \ | |
echo "\w \$ "; \ | |
fi)' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment