From 0daf7a6429ffe8657d61d16e982b05ba9e97951e Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sat, 25 Jun 2022 22:03:12 +0200 Subject: [zshrc]: add custom PROMPT with vcs_info --- zshrc | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'zshrc') diff --git a/zshrc b/zshrc index bffa38e..24790f3 100644 --- a/zshrc +++ b/zshrc @@ -75,7 +75,7 @@ zshPlug 'zsh-users/zsh-autosuggestions' zshPlug 'chriskempson/base16-shell' # MesloLGS font: https://github.com/romkatv/powerlevel10k#manual-font-installation # eg: wget -P ~/.fonts https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf -zshPlug 'romkatv/powerlevel10k.git' -i powerlevel10k.zsh-theme +#zshPlug 'romkatv/powerlevel10k.git' -i powerlevel10k.zsh-theme # }}} # {{{ Key definitions. @@ -263,4 +263,48 @@ fi # }}} +# {{{ vcs_info. + +autoload -Uz vcs_info +precmd () { vcs_info } + +zstyle ':vcs_info:*' enable git +# Enable feature to initialize %u/%c format variables to report unstaged/staged changes. +zstyle ':vcs_info:*' check-for-changes true + +## Format vcs_info_msg_0_ variable. +zstyle ':vcs_info:git:*' formats '[%F{magenta}%b%f] %F{red}%u%F{green}%c%f' +zstyle ':vcs_info:git:*' actionformats '[%F{magenta}%b%f] (%F{red}%a%f) %F{red}%u%F{green}%c%f' + +# Taken from: https://github.com/zsh-users/zsh/blob/cb59dfb3a6f6cce414c5b852c138d5f6bea6d563/Misc/vcs_info-examples#L157 +zstyle ':vcs_info:git*+set-message:*' hooks git-untracked + ++vi-git-untracked() { + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ + git status --porcelain | grep -q '^?? ' 2> /dev/null; then + hook_com[staged]+='%F{yellow}N%f' + fi +} + +# }}} +# {{{ Prompt. + +# Expand variables in $PROMPT. +setopt prompt_subst + +# Prompt utils: +# %F{..) - print text conditionally +# +# %? - last exit code +# %n - user name +# %m - short hostname +# %~ - current path (subst $HONE with ~) +# +# Reference: 'SIMPLE PROMPT ESCAPES' in zshmisc(1). + +PROMPT=$'%n@%m:%F{cyan}%~%f%(?.. %F{red}%?%f) ${vcs_info_msg_0_}\n$ ' + +# }}} + # vim:et:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1 -- cgit v1.2.3