From 5e6ce927a1eecd8b9d34f91bac0cbc25fd2773bc Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Thu, 31 Dec 2015 11:17:16 -0700 Subject: [PATCH] Add git branch to zsh prompt --- zsh/.zshrc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zsh/.zshrc b/zsh/.zshrc index 2bebc68..e50f8c3 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -40,15 +40,22 @@ else local gray="%{$fg[white]%}" fi +function parse_git_branch { + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + echo "${colon}${orange}${ref#refs/heads/}%f" +} + local lbrkt="${gray}[%f" local rbrkt="${gray}]%f" local colon="${gray}:%f" local user="${purple}%n%f" local host="${blue}%m%f" local dir="${green}%~%f" +local branch="\$(parse_git_branch)" +setopt prompt_subst export PROMPT="%# " -export RPROMPT="${lbrkt}${user}${colon}${host}${colon}${dir}${rbrkt}" +export RPROMPT="${lbrkt}${user}${colon}${host}${colon}${dir}${branch}${rbrkt}" # aliases source $HOME/.config/zsh/aliases