# zshrc/85_git_prompt # # Make git information available to the prompt # # Copyright © 1994–2008 martin f. krafft # Released under the terms of the Artistic Licence 2.0 # # Source repository: http://git.madduck.net/v/etc/zsh.git # # Shamelessly adapted from http://www.jukie.net/~bart/conf/zsh.d/S55_git # _get_git_cur_branch() { git branch --no-color | sed -rne 's,^\* ,,p' } _is_git_repo() { [ "$(git rev-parse --is-inside-work-tree)" = true ] } _set_git_psvar() { if _is_git_repo; then psvar[1]="$(_get_git_cur_branch)" else [ -n "$psvar[1]" ] && unset "psvar[1]" fi } update_git_vars_if_git_ran() { # if the last command included the word git, the branch may have changed. # checkout should be alright, but you never know... case "$(history $(($HISTCMD - 1)))" in *git*) _set_git_psvar;; esac } precmd_functions+=update_git_vars_if_git_ran update_git_vars() { _set_git_psvar } chpwd_functions+=update_git_vars # call it once update_git_vars # vim:ft=zsh