]> git.alrj.org Git - zsh.d.git/blob - S60_git
Slightly longer path displayed before the git branch in prompt
[zsh.d.git] / S60_git
1 #! /usr/bin/zsh
2
3 export __ZSH_GIT_BASEDIR=""
4 export __ZSH_GIT_BRANCH=""
5 export __ZSH_GIT_SUBDIR=""
6 export __ZSH_GIT_STATE=""
7 export __ZSH_GIT_VARS_INVALID=1
8
9 git_parse() {
10
11     psvar=()
12     local git_dir ref base_dir sub_dir action branch
13
14     git_dir=$(git rev-parse --git-dir 2> /dev/null) || return
15
16     base_dir=${$(readlink -f "$git_dir/..")/$HOME/'~'}
17
18     sub_dir=$(git rev-parse --show-prefix)
19     sub_dir=${sub_dir%/}
20     ref=$(git symbolic-ref HEAD 2> /dev/null) || return
21
22     psvar[3]=""
23
24     if [ -d "$git_dir/../.dotest" ]; then
25       if [ -f "$git_dir/../.dotest/rebasing" ]; then
26         psvar[3]="-rebase"
27       elif [ -f "$git_dir/../.dotest/applying" ]; then
28         psvar[3]="-am"
29       else
30         psvar[3]="-am-rebase"
31       fi
32       branch="$ref"
33     elif [ -f "$git_dir/.dotest-merge/interactive" ]; then
34       psvar[3]="-rebase-i"
35       branch="$(cat "$git_dir/.dotest-merge/head-name")"
36     elif [ -d "$git_dir/.dotest-merge" ]; then
37       psvar[3]="-rebase-m"
38       branch="$(cat "$git_dir/.dotest-merge/head-name")"
39     elif [ -f "$git_dir/MERGE_HEAD" ]; then
40       psvar[3]="-merge"
41       branch="$ref"
42     else
43       test -f "$git_dir/BISECT_LOG" && psvar[3]="bisect"
44       branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
45         branch="$(git describe --exact-match HEAD 2>/dev/null)" || \
46         branch="$(cut -c1-7 "$git_dir/HEAD")..."
47     fi
48
49     # Got here, we're in git
50     psvar[4]=${branch#refs/heads/}
51     psvar[5]=${base_dir}
52     psvar[6]=${sub_dir}
53 }
54
55 precmd_functions+='git_parse'