Last active
December 12, 2016 11:35
-
-
Save ollieatkinson/c649d8c85aef714acd63 to your computer and use it in GitHub Desktop.
PS1 for git repositories
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
function branch_status { | |
branch=`branch` | |
[ -n "$branch" ] && echo "[$branch`dirty_status`] " || echo | |
} | |
function branch { | |
git branch | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
} | |
function dirty_status { | |
git status --porcelain | ( | |
unset dirty deleted untracked newfile copied renamed | |
while read line ; do | |
case "${line//[[:space:]]/}" in | |
@('M'|'UU')*) dirty='!' ; ;; | |
'D'*) deleted='x' ; ;; | |
'??'*) untracked='?' ; ;; | |
'A'*) newfile='+' ; ;; | |
'C'*) copied='*' ; ;; | |
'R'*) renamed='>' ; ;; | |
esac | |
done | |
bits="$dirty$deleted$untracked$newfile$copied$renamed" | |
[ -n "$bits" ] && echo " $bits" || echo | |
) | |
} | |
export PS1="\w \[\e[0;33m\]\`branch_status\`\[\e[0m\]\\$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment