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 if [[ "$(git rev-parse --is-bare-repository)" == "true" ]]; then
99 base_dir=${$(readlink -f "$git_dir")/$HOME/'~'}
100 sub_dir=${$(pwd)#$(readlink -f "$git_dir")}
102 base_dir=${$(readlink -f "$git_dir/..")/$HOME/'~'}
103 sub_dir=${$(pwd)#$(readlink -f "$git_dir/..")}
107 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
111 if [ -d "$git_dir/../.dotest" ]; then
112 if [ -f "$git_dir/../.dotest/rebasing" ]; then
114 elif [ -f "$git_dir/../.dotest/applying" ]; then
120 elif [ -f "$git_dir/.dotest-merge/interactive" ]; then
122 branch="$(cat "$git_dir/.dotest-merge/head-name")"
123 elif [ -d "$git_dir/.dotest-merge" ]; then
125 branch="$(cat "$git_dir/.dotest-merge/head-name")"
126 elif [ -f "$git_dir/MERGE_HEAD" ]; then
130 test -f "$git_dir/BISECT_LOG" && psvar[3]="bisect"
131 branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
132 branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
133 branch="$(cut -c1-7 "$git_dir/HEAD")..."
137 gitstatus=`git_get_status`
139 # Got here, we're in git
141 psvar[6]=${branch#refs/heads/}
144 psvar[9]=${gitstatus}
147 __ZSH_GIT_BASEDIR="${base_dir}"
148 __ZSH_GIT_SUBDIR="${sub_dir}"
149 __ZSH_GIT_BRANCH="${branch#refs/heads/}"
150 __ZSH_GIT_ACTION="${action}"
151 __ZSH_GIT_STATUS="${gitstatus}"
153 __ZSH_GIT_VARS_INVALID=0
154 __ZSH_GIT_STATUS_INVALID=0
158 chpwd_functions+='git_chpwd'
159 preexec_functions+='git_preexec'
160 precmd_functions+='git_parse'