owenrusk.dev

dotfiles

shell, editor, ssh.

git clone https://owenrusk.dev/dotfiles.git

commit be8acc710adb0de092c6ceb5439aae27c2f53b93
parent 1d34d86ef2c75fba466e9574829e540d825e9138
author Owen Rusk <owen@papermothgames.com>
date   2024-03-20 17:30:12 -0500
zsh: git branch in the prompt
zsh/zshrc+8-1
diff --git a/zsh/zshrc b/zsh/zshrc
index 37da1f3..00d535d 100644
--- a/zsh/zshrc
+++ b/zsh/zshrc
@@ -14,7 +14,14 @@ compinit -d ~/.cache/zcompdump
 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
 zstyle ':completion:*' menu select
 
-PROMPT='%F{8}%m%f %F{blue}%~%f %(?..%F{red}%?%f )%# '
+# host, directory, git branch, and the exit code when it isn't zero
+autoload -Uz vcs_info add-zsh-hook
+zstyle ':vcs_info:*' enable git
+zstyle ':vcs_info:git:*' formats ' %b'
+zstyle ':vcs_info:git:*' actionformats ' %b|%a'
+add-zsh-hook precmd vcs_info
+setopt prompt_subst
+PROMPT='%F{8}%m%f %F{blue}%~%f%F{yellow}${vcs_info_msg_0_}%f %(?..%F{red}%?%f )%# '
 
 # ~/.zshrc is a link. follow it back here.
 dots=${${(%):-%x}:A:h}