X-Git-Url: https://git.madduck.net/etc/zsh.git/blobdiff_plain/71a3a8fffb9b2544b5ec901045ed49b969f65dde..429bc5d0944d0553c6949561f41abe40e2e05601:/.zsh/zshrc/85_git_prompt diff --git a/.zsh/zshrc/85_git_prompt b/.zsh/zshrc/85_git_prompt new file mode 100644 index 0000000..9d05cca --- /dev/null +++ b/.zsh/zshrc/85_git_prompt @@ -0,0 +1,46 @@ +# 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 + 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