From 1fea4777fadeedb475ccd38bce26a3e5dad2e70b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 Jan 2022 22:06:52 +0530 Subject: [PATCH] zsh shell integration: Restore cursor to blinking block before running external commands --- shell-integration/zsh/kitty-integration | 33 ++++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/shell-integration/zsh/kitty-integration b/shell-integration/zsh/kitty-integration index e9b6511da..745d2c406 100644 --- a/shell-integration/zsh/kitty-integration +++ b/shell-integration/zsh/kitty-integration @@ -119,21 +119,6 @@ _ksi_deferred_init() { fpath=($comp_dir ${fpath:#$comp_dir}) fi - # Enable cursor shape changes depending on the current keymap. - if (( ! opt[(Ie)no-cursor] )); then - # This implementation leaks blinking block cursor into external commands - # executed from zle. For example, users of fzf-based widgets may find - # themselves with a blinking block cursor within fzf. - _ksi_zle_line_init _ksi_zle_line_finish _ksi_zle_keymap_select() { - case ${KEYMAP-} in - # Blinking block cursor. - vicmd|visual) builtin print -nu "$_ksi_fd" '\e[1 q';; - # Blinking bar cursor. - *) builtin print -nu "$_ksi_fd" '\e[5 q';; - esac - } - fi - # Enable semantic markup with OSC 133. if (( ! opt[(Ie)no-prompt-mark] )); then _ksi_precmd() { @@ -253,6 +238,24 @@ _ksi_deferred_init() { builtin print -rnu $_ksi_fd \$'\\e]2;'\"\${(V)1}\"\$'\\a'" fi + # Enable cursor shape changes depending on the current keymap. + if (( ! opt[(Ie)no-cursor] )); then + # This implementation leaks blinking block cursor into external commands + # executed from zle. For example, users of fzf-based widgets may find + # themselves with a blinking block cursor within fzf. + _ksi_zle_line_init _ksi_zle_line_finish _ksi_zle_keymap_select() { + case ${KEYMAP-} in + # Blinking block cursor. + vicmd|visual) builtin print -nu "$_ksi_fd" '\e[1 q';; + # Blinking bar cursor. + *) builtin print -nu "$_ksi_fd" '\e[5 q';; + esac + } + functions[_ksi_preexec]+=" + builtin print -rnu $_ksi_fd \$'\\e[1 q'" + fi + + # Some zsh users manually run `source ~/.zshrc` in order to apply rc file # changes to the current shell. This is a terrible practice that breaks many # things, including our shell integration. For example, Oh My Zsh and Prezto