Skip to content

Instantly share code, notes, and snippets.

@ollieatkinson
Last active December 12, 2016 11:35
Show Gist options
  • Save ollieatkinson/c649d8c85aef714acd63 to your computer and use it in GitHub Desktop.
Save ollieatkinson/c649d8c85aef714acd63 to your computer and use it in GitHub Desktop.
PS1 for git repositories
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