From 895d0ff0aa1caa207564155a76b2defcca709089 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Mon, 18 Oct 2021 10:08:33 +0000 Subject: [PATCH] zsh: Print `normal` in RPROMPT in Vim mode Change the cursor to an `_` too, to make it abundantly clear that the mode has changed. Hopefully this stops me screwing up and accidentally entering vim mode without realising. Signed-off-by: Joe Groocock --- zsh/plugins/fish-theme.zsh | 16 +++++++++++++++- zsh/plugins/git-rprompt.zsh | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/zsh/plugins/fish-theme.zsh b/zsh/plugins/fish-theme.zsh index db46577..0e177c7 100644 --- a/zsh/plugins/fish-theme.zsh +++ b/zsh/plugins/fish-theme.zsh @@ -4,6 +4,16 @@ _fishy_collapsed_wd() { pwd | sed -E 's|^'$HOME'|~|;s|(.*)/|\1%|;s|((^\|/)\.?[^/%]{1})[^/%]*|\1|g;s|(.*)%|\1/|' } +function zle-line-init zle-keymap-select { + case $KEYMAP in + vicmd) printf '\e[3 q';; # block cursor + *) printf '\e[2 q';; # less visible cursor + esac + zle reset-prompt +} +zle -N zle-line-init +zle -N zle-keymap-select + # Required for dynamic prompt setopt prompt_subst @@ -11,4 +21,8 @@ local user_color='green'; [ $UID -eq 0 ] && user_color='red' PROMPT="%n@%m %F{$user_color}\$(_fishy_collapsed_wd)%f%(!.#.>) " PROMPT2='%F{red}\ %f' -RPROMPT='%F{red}%(?.. %?)%f' +RPROMPT='%F{cyan}${${KEYMAP/vicmd/ normal}/(main|viins)/}%f%(?.. %F{red}%?%f)' + +# Disable trailing space +# https://superuser.com/questions/655607/removing-the-useless-space-at-the-end-of-the-right-prompt-of-zsh-rprompt +ZLE_RPROMPT_INDENT=0 diff --git a/zsh/plugins/git-rprompt.zsh b/zsh/plugins/git-rprompt.zsh index 4f6b52d..c7b00ab 100644 --- a/zsh/plugins/git-rprompt.zsh +++ b/zsh/plugins/git-rprompt.zsh @@ -57,7 +57,7 @@ git_prompt_status() { # Required for dynamic prompt setopt prompt_subst -ZSH_THEME_GIT_PROMPT_PREFIX=" " +ZSH_THEME_GIT_PROMPT_PREFIX="" ZSH_THEME_GIT_PROMPT_SUFFIX="" ZSH_THEME_GIT_PROMPT_DIRTY="" ZSH_THEME_GIT_PROMPT_CLEAN=""