From 429bc5d0944d0553c6949561f41abe40e2e05601 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Mon, 5 May 2008 19:50:03 +0100 Subject: [PATCH] add git branch to prompt --- .zsh/zshrc/85_git_prompt | 46 ++++++++++++++++++++++++++++++++++++++++ .zsh/zshrc/90_prompt | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .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 diff --git a/.zsh/zshrc/90_prompt b/.zsh/zshrc/90_prompt index 0abe132..afd13b2 100644 --- a/.zsh/zshrc/90_prompt +++ b/.zsh/zshrc/90_prompt @@ -11,6 +11,6 @@ is_root && PS1_HL=U PS1="%${PS1_HL:=B}%m%${(L)PS1_HL}:%25<..<%~%# " unset PS1_HL -RPS1="#[%(0?..%?,)%!]%v" +RPS1="#%(1v.%1v,.)%(0?..%?,)%!" # vim:ft=zsh -- 2.39.5