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 || \
43 $(echo ${gitstat} | grep -c "^\# Changes not staged for commit:$") > 0 ]]; then
44 gitstatus="${gitstatus}!"
47 if [[ $(echo ${gitstat} | grep -c "^# Untracked files:$") > 0 ]]; then
48 gitstatus="${gitstatus}?"
56 # psvar[5] == current action (merge, rebase, ...)
57 # psvar[6] == current branch
58 # psvar[7] == repository base directory
59 # psvar[8] == current subdir into repository
60 # psvar[9] == status (untracked, unstaged, staged)
62 local git_dir ref base_dir sub_dir action branch gitstat gitstatus
65 # If nothing has been invalidated
66 if [[ "${__ZSH_GIT_VARS_INVALID}" == "0" && "${__ZSH_GIT_STATUS_INVALID}" == "0" ]]; then
68 # reuse previous values
69 psvar[5]=${__ZSH_GIT_ACTION}
70 psvar[6]=${__ZSH_GIT_BRANCH}
71 psvar[7]=${__ZSH_GIT_BASEDIR}
72 psvar[8]=${__ZSH_GIT_SUBDIR}
73 psvar[9]=${__ZSH_GIT_STATUS}
78 # If only status has been invalidated
79 if [[ "${__ZSH_GIT_VARS_INVALID}" == "0" && "${__ZSH_GIT_STATUS_INVALID}" == "1" ]]; then
81 # reuse previous values
82 psvar[5]=${__ZSH_GIT_ACTION}
83 psvar[6]=${__ZSH_GIT_BRANCH}
84 psvar[7]=${__ZSH_GIT_BASEDIR}
85 psvar[8]=${__ZSH_GIT_SUBDIR}
87 __ZSH_GIT_STATUS=$(git_get_status)
88 psvar[9]=${__ZSH_GIT_STATUS}
90 __ZSH_GIT_STATUS_INVALID=0
95 # Git prompt variables are invalid. Update them.
97 git_dir=$(git rev-parse --git-dir 2> /dev/null) || return
99 if [[ "$(git rev-parse --is-bare-repository)" == "true" ]]; then
100 base_dir=${$(readlink -f "$git_dir")/$HOME/'~'}
101 sub_dir=${$(pwd)#$(readlink -f "$git_dir")}
103 base_dir=${$(readlink -f "$git_dir/..")/$HOME/'~'}
104 sub_dir=${$(pwd)#$(readlink -f "$git_dir/..")}
108 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
112 if [ -d "$git_dir/../.dotest" ]; then
113 if [ -f "$git_dir/../.dotest/rebasing" ]; then
115 elif [ -f "$git_dir/../.dotest/applying" ]; then
121 elif [ -f "$git_dir/.dotest-merge/interactive" ]; then
123 branch="$(cat "$git_dir/.dotest-merge/head-name")"
124 elif [ -d "$git_dir/.dotest-merge" ]; then
126 branch="$(cat "$git_dir/.dotest-merge/head-name")"
127 elif [ -f "$git_dir/MERGE_HEAD" ]; then
131 test -f "$git_dir/BISECT_LOG" && psvar[3]="bisect"
132 branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
133 branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
134 branch="$(cut -c1-7 "$git_dir/HEAD")..."
138 gitstatus=`git_get_status`
140 # Got here, we're in git
142 psvar[6]=${branch#refs/heads/}
145 psvar[9]=${gitstatus}
148 __ZSH_GIT_BASEDIR="${base_dir}"
149 __ZSH_GIT_SUBDIR="${sub_dir}"
150 __ZSH_GIT_BRANCH="${branch#refs/heads/}"
151 __ZSH_GIT_ACTION="${action}"
152 __ZSH_GIT_STATUS="${gitstatus}"
154 __ZSH_GIT_VARS_INVALID=0
155 __ZSH_GIT_STATUS_INVALID=0
159 chpwd_functions+='git_chpwd'
160 preexec_functions+='git_preexec'
161 precmd_functions+='git_parse'