summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2022-06-25 22:03:12 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2022-06-25 22:03:12 +0200
commit0daf7a6429ffe8657d61d16e982b05ba9e97951e (patch)
tree731adab5d909a2fde53a89092142a81e1d3e1105
parenta2b7188b7f5c6deac15c2c4741b2bc23b68be283 (diff)
downloaddotfiles-0daf7a6429ffe8657d61d16e982b05ba9e97951e.tar.gz
dotfiles-0daf7a6429ffe8657d61d16e982b05ba9e97951e.zip
[zshrc]: add custom PROMPT with vcs_info
-rw-r--r--zshrc46
1 files changed, 45 insertions, 1 deletions
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{<color} / %f - change color / clear color
+# %(<cond>.<Y txt>.<N txt>) - 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