summary refs log tree commit diff
path: root/.zsh/gitprompt.zsh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.zsh/gitprompt.zsh68
1 files changed, 31 insertions, 37 deletions
diff --git a/.zsh/gitprompt.zsh b/.zsh/gitprompt.zsh
index 0a420786..433481b9 100644
--- a/.zsh/gitprompt.zsh
+++ b/.zsh/gitprompt.zsh
@@ -1,50 +1,50 @@
 # Ported from http://sebastiancelis.com/2009/11/16/zsh-prompt-git-users/
 
-function gitprompt_update
-{
-  unset __CURRENT_GIT_BRANCH
-  unset __CURRENT_GIT_BRANCH_STATUS
-  unset __CURRENT_GIT_BRANCH_IS_DIRTY
+function _gitprompt_update {
+  unset _git_branch
+  unset _git_status
+  unset _git_dirty
 
-  local st="$(git status 2>/dev/null)"
+  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'
+      _git_branch='none'
     else
-      __CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
+      _git_branch="${arr[1][(w)-1]}"
     fi
 
     if [[ $arr[2] =~ 'Your branch is' ]]; then
       if [[ $arr[2] =~ 'ahead' ]]; then
-        __CURRENT_GIT_BRANCH_STATUS='ahead'
+        _git_status='ahead'
       elif [[ $arr[2] =~ 'diverged' ]]; then
-        __CURRENT_GIT_BRANCH_STATUS='diverged'
+        _git_status='diverged'
       else
-        __CURRENT_GIT_BRANCH_STATUS='behind'
+        _git_status='behind'
       fi
     fi
 
-    if [[ ! $st =~ 'nothing' ]]; then # Untracked files count as clean
-      __CURRENT_GIT_BRANCH_IS_DIRTY='1'
+    if [[ ! $st =~ 'nothing' ]]; then
+      _git_dirty=1
     fi
   fi
 }
 
-# Changed around the formatting here a bunch
-function gitprompt
-{
-  if [ -n "$__CURRENT_GIT_BRANCH" ]; then
-    local s="%{${fg[yellow]}%}"
-    if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then
+function gitprompt {
+  if [[ -n "$_git_branch" ]]; then
+    local s
+    [[ -z "$1" ]] && s="%{${fg[yellow]}%}"
+
+    if [[ -n "$_git_dirty" ]]; then
       s+="⚡"
     else
       s+=":"
     fi
-    s+="$__CURRENT_GIT_BRANCH"
-    case "$__CURRENT_GIT_BRANCH_STATUS" in
+
+    s+="$_git_branch"
+    case "$_git_status" in
       ahead)
         s+="↑"
         ;;
@@ -56,24 +56,18 @@ function gitprompt
         ;;
     esac
 
-    echo $s
+    echo "$s"
   fi
 }
 
-function gitprompt_preexec
-{
-  case "$1" in
-    g*) # Switched from git* to also detect my short aliases
-      __EXECUTED_GIT_COMMAND=1
-      ;;
-  esac
+function _gitprompt_preexec {
+  [[ "$1" =~ "^g" ]] && _git_command=1
 }
 
-function gitprompt_precmd
-{
-  if [ -n "$__EXECUTED_GIT_COMMAND" ]; then
-    gitprompt_update
-    unset __EXECUTED_GIT_COMMAND
+function _gitprompt_precmd {
+  if [[ -n "$_git_command" ]]; then
+    _gitprompt_update
+    unset _git_command
   fi
 }
 
@@ -81,6 +75,6 @@ typeset -ga preexec_functions
 typeset -ga precmd_functions
 typeset -ga chpwd_functions
 
-preexec_functions+='gitprompt_preexec'
-precmd_functions+='gitprompt_precmd'
-chpwd_functions+='gitprompt_update'
+preexec_functions+='_gitprompt_preexec'
+precmd_functions+='_gitprompt_precmd'
+chpwd_functions+='_gitprompt_update'