From: Sergey Matveev <stargrave@stargrave.org>
Date: Sun, 13 Feb 2022 11:40:38 +0000 (+0300)
Subject: Git VCS in zsh prompt
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=9e0a9b2f9d90cf0846f4719b03bde806c301543c;p=dotfiles.git

Git VCS in zsh prompt
---

diff --git a/zsh/.zsh/rc/010vcs.zsh b/zsh/.zsh/rc/010vcs.zsh
new file mode 100644
index 0000000..e34b617
--- /dev/null
+++ b/zsh/.zsh/rc/010vcs.zsh
@@ -0,0 +1,6 @@
+autoload -Uz vcs_info
+zstyle ":vcs_info:*" enable git
+zstyle ":vcs_info:*" max-exports 1
+zstyle ":vcs_info:*" get-revision true
+zstyle ":vcs_info:*" formats "%i"
+zstyle ":vcs_info:*" actionformats "%a|%i"
diff --git a/zsh/.zsh/rc/015prompt.zsh b/zsh/.zsh/rc/015prompt.zsh
index cdbd0fa..3ffbab9 100644
--- a/zsh/.zsh/rc/015prompt.zsh
+++ b/zsh/.zsh/rc/015prompt.zsh
@@ -1,10 +1,16 @@
 function zle-line-init zle-keymap-select {
-    local state="%#" timer_val="?"
+    prompt="%2~ %B"
+    [[ "$#_autoenv_stack_entered" -gt 0 ]] && prompt+="A"
+    [[ -n "$VIRTUAL_ENV" ]] && prompt+="V"
+    prompt+="%(1j.%j.)%b"
+    prompt+="%U${vcs_info_msg_0_[1,-32]}%u"
+    prompt+="%(?..%S%?%s)"
+    [[ $timer ]] && {
+        local val=$(( $SECONDS - $timer ))
+        [[ $val -gt 0 ]] && prompt+="%U${val}%u"
+    }
+    local state="%#"
     [[ ${KEYMAP} == vicmd ]] && state="+"
-    [[ $timer ]] && timer_val=$(( $SECONDS - $timer ))
-    prompt="%2~ "
-    prompt+="%U${timer_val}%u|"
-    prompt+="%B%?%b"
     prompt+="%B%F{magenta}${state}%f%b "
     PS1=$prompt
     zle reset-prompt
@@ -18,4 +24,5 @@ preexec() {
 
 precmd() {
     printf "\a\033]2;\033\\"
+    vcs_info
 }