8 __ZSH_GIT_VARS_INVALID=1
9 __ZSH_GIT_STATUS_INVALID=1
13 # On cd, invalidate git status in prompt
14 __ZSH_GIT_VARS_INVALID=1
19 # On git command, invalidate git status in prompt
22 __ZSH_GIT_VARS_INVALID=1
26 # *any* command could invalidate the repository status (new file, ...)
27 __ZSH_GIT_STATUS_INVALID=1
32 # Return only git status
33 local gitstat gitstatus
35 gitstat=$(git status 2> /dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
38 if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
42 if [[ $(echo ${gitstat} | grep -c "^\# Changed but not updated:$") > 0 ]]; then
43 gitstatus="${gitstatus}!"
46 if [[ $(echo ${gitstat} | grep -c "^# Untracked files:$") > 0 ]]; then
47 gitstatus="${gitstatus}?"
55 # psvar[5] == current action (merge, rebase, ...)
56 # psvar[6] == current branch
57 # psvar[7] == repository base directory
58 # psvar[8] == current subdir into repository
59 # psvar[9] == status (untracked, unstaged, staged)
61 local git_dir ref base_dir sub_dir action branch gitstat gitstatus
64 # If nothing has been invalidated
65 if [[ "${__ZSH_GIT_VARS_INVALID}" == "0" && "${__ZSH_GIT_STATUS_INVALID}" == "0" ]]; then
67 # reuse previous values
68 psvar[5]=${__ZSH_GIT_ACTION}
69 psvar[6]=${__ZSH_GIT_BRANCH}
70 psvar[7]=${__ZSH_GIT_BASEDIR}
71 psvar[8]=${__ZSH_GIT_SUBDIR}
72 psvar[9]=${__ZSH_GIT_STATUS}
77 # If only status has been invalidated
78 if [[ "${__ZSH_GIT_VARS_INVALID}" == "0" && "${__ZSH_GIT_STATUS_INVALID}" == "1" ]]; then
80 # reuse previous values
81 psvar[5]=${__ZSH_GIT_ACTION}
82 psvar[6]=${__ZSH_GIT_BRANCH}
83 psvar[7]=${__ZSH_GIT_BASEDIR}
84 psvar[8]=${__ZSH_GIT_SUBDIR}
86 __ZSH_GIT_STATUS=$(git_get_status)
87 psvar[9]=${__ZSH_GIT_STATUS}
89 __ZSH_GIT_STATUS_INVALID=0
94 # Git prompt variables are invalid. Update them.
96 git_dir=$(git rev-parse --git-dir 2> /dev/null) || return
98 base_dir=${$(readlink -f "$git_dir/..")/$HOME/'~'}
100 sub_dir=$(git rev-parse --show-prefix)
102 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
106 if [ -d "$git_dir/../.dotest" ]; then
107 if [ -f "$git_dir/../.dotest/rebasing" ]; then
109 elif [ -f "$git_dir/../.dotest/applying" ]; then
115 elif [ -f "$git_dir/.dotest-merge/interactive" ]; then
117 branch="$(cat "$git_dir/.dotest-merge/head-name")"
118 elif [ -d "$git_dir/.dotest-merge" ]; then
120 branch="$(cat "$git_dir/.dotest-merge/head-name")"
121 elif [ -f "$git_dir/MERGE_HEAD" ]; then
125 test -f "$git_dir/BISECT_LOG" && psvar[3]="bisect"
126 branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
127 branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
128 branch="$(cut -c1-7 "$git_dir/HEAD")..."
132 gitstatus=`git_get_status`
134 # Got here, we're in git
136 psvar[6]=${branch#refs/heads/}
139 psvar[9]=${gitstatus}
142 __ZSH_GIT_BASEDIR="${base_dir}"
143 __ZSH_GIT_SUBDIR="${sub_dir}"
144 __ZSH_GIT_BRANCH="${branch#refs/heads/}"
145 __ZSH_GIT_ACTION="${action}"
146 __ZSH_GIT_STATUS="${gitstatus}"
148 __ZSH_GIT_VARS_INVALID=0
149 __ZSH_GIT_STATUS_INVALID=0
153 chpwd_functions+='git_chpwd'
154 preexec_functions+='git_preexec'
155 precmd_functions+='git_parse'