# bashrc extra functions written for AOSC OSes, package "git"
# by Arthur Wang

# Aliases, mostly from http://blog.sina.com.cn/s/blog_630c58cb01011uid.html
alias g="git status"
alias ga="git add"
alias gaa="git add ."
alias gau="git add -u"
alias gct="git commit"
alias gcm="git commit -m"
alias gca="git commit -am"
alias gb="git branch"
alias gbd="git branch -d"
alias gco="git checkout"
alias gcob="git checkout -b"
alias gt="git stash"
alias gta="git stash apply"
alias gmg="git merge"
alias gr="git rebase"
alias gl="git log --oneline --decorate --graph"
alias gsh="git show"
alias gd="git diff"
alias gdc="git diff --cached"
alias gbl="git blame"
alias gps="git push"
alias gpl="git pull"


# Prompt
alias __git_branch="git branch 2>/dev/null | grep '*' | sed 's/*\ //g'"

# From http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
# Modified.
_git_status() {
	local gbr
	gbr=$(git branch 2>/dev/null) || return 1
	gbr=$(printf %s "$gbr" | grep '*' | sed 's/*\ //g')
	local gst
	gst=$(LC_ALL=C git status 2>&1)
	if printf %s "$gst" | grep -q "nothing to commit"; then
		 echo -e "\01\e[1m\02@\01\e[0;32m\0002$gbr\01\e[0m\02"
	elif printf %s "$gst" | grep -q "nothing added to commit"; then # Untracked
		 echo -e "\01\e[1m\02@\01\e[0;35m\0002$gbr\01\e[0m\02"
	elif printf %s "$gst" | grep -q "must be run in a work tree"; then # Not in work tree
		 echo -e "\01\e[1m\02@\01\e[0;37m\0002$gbr\01\e[0m\02"
	else  # Change not added/not merged yet
		 echo -e "\01\e[1m\02@\01$IRED\0002$gbr\01\e[0m\02"
	fi
}

# A shorter one without color
# alias _git_status='_st="$(__git_branch)"; ((!PIPESTATUS[0])) && echo "@$_st"'
# For users of the contrib/completion __git_ps1
# _git_status(){ git branch &>/dev/null || return 1; echo -n ' '; __git_ps1; }
