From 9e0a9b2f9d90cf0846f4719b03bde806c301543c Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 13 Feb 2022 14:40:38 +0300 Subject: [PATCH] Git VCS in zsh prompt --- zsh/.zsh/rc/010vcs.zsh | 6 ++++++ zsh/.zsh/rc/015prompt.zsh | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 zsh/.zsh/rc/010vcs.zsh 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 } -- 2.44.0