-export __ZSH_GIT_BASEDIR=""
-export __ZSH_GIT_BRANCH=""
-export __ZSH_GIT_SUBDIR=""
-export __ZSH_GIT_STATE=""
-export __ZSH_GIT_VARS_INVALID=1
+# Those can be used, for instance to construct the prompt:
+__ZSH_GIT_BASEDIR=""
+__ZSH_GIT_SUBDIR=""
+__ZSH_GIT_BRANCH=""
+__ZSH_GIT_ACTION=""
+__ZSH_GIT_STATUS=""
+
+__ZSH_GIT_VARS_INVALID=1
+__ZSH_GIT_STATUS_INVALID=1
+
+
+git_chpwd() {
+ # On cd, invalidate git status in prompt
+ __ZSH_GIT_VARS_INVALID=1
+ __ZSH_GIT_BASEDIR=""
+}
+
+
+git_preexec() {
+ # On git command, invalidate git status in prompt
+ case "$1" in
+ git*)
+ __ZSH_GIT_VARS_INVALID=1
+ ;;
+ esac
+
+ # *any* command could invalidate the repository status (new file, ...)
+ __ZSH_GIT_STATUS_INVALID=1
+}
+
+git_get_status() {
+ # Return only git status
+ local gitstat gitstatus
+
+ gitstat=$(LANG=C git status 2> /dev/null | grep '\(Untracked\|Changes\|Changed but not updated:\)')
+ # 'fix for mcedit parser
+ gitstatus=""
+
+ if [[ $(echo ${gitstat} | grep -c "^Changes to be committed:$") > 0 ]]; then
+ gitstatus='✚'
+ fi
+
+ if [[ $(echo ${gitstat} | grep -c "^Changed but not updated:$") > 0 || \
+ $(echo ${gitstat} | grep -c "^Changes not staged for commit:$") > 0 ]]; then
+ gitstatus="${gitstatus}✹"
+ fi
+
+ if [[ $(echo ${gitstat} | grep -c "^Untracked files:$") > 0 ]]; then
+ gitstatus="${gitstatus}★"
+ fi
+
+ if [[ -z $gitstatus ]]; then
+ gitstatus="%{${fg_bold[green]}%}✔%{$reset_color%}"
+ else
+ gitstatus="%{${fg_bold[yellow]}%}$gitstatus%{$reset_color%}"
+ fi
+
+ echo $gitstatus
+}
+