Last active
August 29, 2015 14:06
-
-
Save arktisklada/117cb0bdbbb56afad29d to your computer and use it in GitHub Desktop.
git_prompt method to include git branch and significant symbols in bash prompt
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
git_prompt () { | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
return 0 | |
fi | |
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
status='' | |
# Ensure the index is up to date. | |
git update-index --really-refresh -q &>/dev/null; | |
# Check for unstaged changes. | |
if ! $(git diff-files --quiet --ignore-submodules --); then | |
status+='+'; | |
fi | |
# Check for uncommitted changes in the index. | |
if ! $(git diff --quiet --ignore-submodules --cached); then | |
status+='*'; | |
fi | |
# Check for untracked files. | |
if [ -n "$(git ls-files --others --exclude-standard)" ]; then | |
status+='?'; | |
fi | |
# Check for unpushed commits. | |
if [ -n "$(git unpushed)" ]; then | |
status+='↑'; | |
fi | |
if [ -n "$status" ]; then | |
status=" $status"; | |
fi | |
echo " [git:$git_branch$status]" | |
} | |
PS1='\h:\W$(git_prompt)\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment