ohmyzsh/lib/git.zsh
2010-01-20 12:12:48 -05:00

45 lines
1.3 KiB
Bash

# get the name of the branch we are on
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
parse_git_dirty () {
gitstat=$(git status 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY"
fi
if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then
echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
if [[ $(echo ${gitstat} | wc -l | tr -d ' ') == 0 ]]; then
echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
#
# Will return the current branch name
# Usage example: git pull origin $(current_branch)
#
function current_branch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
# Aliases
alias g='git'
alias gst='git status'
alias gl='git pull'
alias gup='git fetch && git rebase'
alias gp='git push'
alias gd='git diff | mate'
alias gdv='git diff -w "$@" | vim -R -'
alias gc='git commit -v'
alias gca='git commit -v -a'
alias gb='git branch'
alias gba='git branch -a'
alias gcount='git shortlog -sn'
alias gcp='git cherry-pick'