Skip to content

Commit

Permalink
added zsh functions for git
Browse files Browse the repository at this point in the history
  • Loading branch information
three18ti committed Mar 6, 2012
1 parent 65616e1 commit 7676c88
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .zsh/functions/chpwd_update_git_vars
@@ -0,0 +1 @@
update_current_git_vars
4 changes: 4 additions & 0 deletions .zsh/functions/precmd_update_git_vars
@@ -0,0 +1,4 @@
if [ -n "$__EXECUTED_GIT_COMMAND" ]; then
update_current_git_vars
unset __EXECUTED_GIT_COMMAND
fi
7 changes: 7 additions & 0 deletions .zsh/functions/preexec_update_git_vars
@@ -0,0 +1,7 @@
case "$1" in
git*)
__EXECUTED_GIT_COMMAND=1
;;
esac


21 changes: 21 additions & 0 deletions .zsh/functions/prompt_git_info
@@ -0,0 +1,21 @@
if [ -n "$__CURRENT_GIT_BRANCH" ]; then
local s="("
s+="$__CURRENT_GIT_BRANCH"
case "$__CURRENT_GIT_BRANCH_STATUS" in
ahead)
s+="↑"
;;
diverged)
s+="↕"
;;
behind)
s+="↓"
;;
esac
if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then
s+="⚡"
fi
s+=")"

printf " %s%s" "%{${fg[yellow]}%}" $s
fi
29 changes: 29 additions & 0 deletions .zsh/functions/update_current_git_vars
@@ -0,0 +1,29 @@
unset __CURRENT_GIT_BRANCH
unset __CURRENT_GIT_BRANCH_STATUS
unset __CURRENT_GIT_BRANCH_IS_DIRTY

local st="$(git status 2>/dev/null)"
if [[ -n "$st" ]]; then
local -a arr
arr=(${(f)st})

if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
__CURRENT_GIT_BRANCH='no-branch'
else
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
fi

if [[ $arr[2] =~ 'Your branch is' ]]; then
if [[ $arr[2] =~ 'ahead' ]]; then
__CURRENT_GIT_BRANCH_STATUS='ahead'
elif [[ $arr[2] =~ 'diverged' ]]; then
__CURRENT_GIT_BRANCH_STATUS='diverged'
else
__CURRENT_GIT_BRANCH_STATUS='behind'
fi
fi

if [[ ! $st =~ 'nothing to commit' ]]; then
__CURRENT_GIT_BRANCH_IS_DIRTY='1'
fi
fi

0 comments on commit 7676c88

Please sign in to comment.