All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 # Make git information available to the prompt
5 # Copyright © 1994–2008 martin f. krafft <madduck@madduck.net>
6 # Released under the terms of the Artistic Licence 2.0
8 # Source repository: http://git.madduck.net/v/etc/zsh.git
10 # Shamelessly based on http://glandium.org/blog/?p=170
16 relroot="$(git rev-parse --show-cdup 2>/dev/null)" || return 1
17 if [ -n "$relroot" ]; then
18 readlink -f "$relroot"
27 ref=$(git symbolic-ref -q HEAD 2>/dev/null \
28 || git-name-rev --name-only HEAD 2>/dev/null)
29 echo "${ref#refs/heads/}"
34 local pwda reporoot loc
37 echo $((1 - $#reporoot)) $(($#pwda - $#reporoot))
40 __get_prompt_path_components()
45 set -- $(__get_root_offsets "$reporoot")
46 if [ "$2" -le 0 ]; then
49 echo "%${1}~" "%${2}~"
56 [ -d .git ] && echo git && break
57 [ -d .bzr ] && echo bzr && break
58 [ -d .hg ] && echo hg && break
59 [ -d .svn ] && echo svn && break
60 [ -d CVS ] && echo cvs && break
61 [ "$PWD" = / ] && echo NONE && return 1
66 __vcs_set_prompt_variables()
70 local repotype="${1:-$(__vcs_get_repo_type)}"
74 local reporoot="$(__git_get_repo_root)"
75 set -- $(__get_prompt_path_components "$reporoot")
76 branch="$(__git_get_branch)"
78 local prelen="$((MAXLEN - $#post - $#branch))"
79 [ $prelen -lt 10 ] && prelen=10
80 pre="%${prelen}<..<${1}%<<"
86 *) warn "$repotype repositories not (yet) supported in the prompt";;
88 local p="%${MAXLEN}<..<%~%<<"
89 #TODO find a better way so we don't have to nuke $psvar, but since the
90 # %(nv.true.false) check for prompts checks element count, not
91 # content, that's all we get for now
102 # too dangerous to be run as root
104 _update_vcs_prompt_vars_if_vcs_ran() {
105 local vcs="$(__vcs_get_repo_type)"
106 case "$(history $(($HISTCMD - 1)))" in
107 # $vcs appeared in last command, so be sure to update
108 *${vcs}*) __vcs_set_prompt_variables
111 precmd_functions+=_update_vcs_prompt_vars_if_vcs_ran
113 _update_vcs_prompt_vars() {
114 __vcs_set_prompt_variables
116 chpwd_functions+=_update_vcs_prompt_vars
119 _update_vcs_prompt_vars