commit 5950ae3fde192858dfc310efb3bd10de9ddd03ad parent 425dffb66c61354c0c71b9336f8afb18479ef0dc Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Sat, 25 May 2019 08:50:52 +0200 Fix cursor shape in zsh Diffstat:
M | .zshrc | | | 31 | +++++++++++++------------------ |
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/.zshrc b/.zshrc @@ -147,6 +147,12 @@ precmd() { fi } +_fix_cursor() { + echo -ne '\e[5 q' + } + +precmd_functions+=(_fix_cursor) + git_branch() { branch_name=$(git symbolic-ref --short HEAD 2> /dev/null) @@ -192,27 +198,16 @@ rprompt() { PROMPT="$(prompt_with_vimode $insert_mode)" RPROMPT="$(rprompt)" -function zle-line-init zle-keymap-select zle-line-finish { - PROMPT=$(prompt_with_vimode \ - ${${KEYMAP/vicmd/$normal_mode}/(main|viins)/$insert_mode}) - RPROMPT=$(rprompt) - - # new start - case $KEYMAP in - # vicmd) print -n -- "\E]50;CursorShape=0\C-G";; # block cursor - # viins|main) print -n -- "\E]50;CursorShape=1\C-G";; # line cursor - vicmd) print -rn -- $terminfo[cvvis];; # block cursor - viins|main) print -rn -- $terminfo[cnorm];; # less visible cursor - esac - # new end +function zle-keymap-select { + if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then + echo -ne '\e[1 q' - zle reset-prompt - zle -R # new + elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || + [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then + echo -ne '\e[5 q' + fi } - -zle -N zle-line-init zle -N zle-keymap-select -zle -N zle-line-finish #### PLUGINS