]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Git VCS in zsh prompt
authorSergey Matveev <stargrave@stargrave.org>
Sun, 13 Feb 2022 11:40:38 +0000 (14:40 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 13 Feb 2022 12:10:55 +0000 (15:10 +0300)
zsh/.zsh/rc/010vcs.zsh [new file with mode: 0644]
zsh/.zsh/rc/015prompt.zsh

diff --git a/zsh/.zsh/rc/010vcs.zsh b/zsh/.zsh/rc/010vcs.zsh
new file mode 100644 (file)
index 0000000..e34b617
--- /dev/null
@@ -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"
index cdbd0faac9423679640101f2b9524cd53640000e..3ffbab91d8b47120830fe74843207f75e7693564 100644 (file)
@@ -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
 }