From db5adc8117ef25d1df61236e834b61da0eb003d5 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 2 Jan 2018 13:36:47 +0000 Subject: [PATCH] Fix cursor shape change bug in tmux Sending escape sequences directly from zsh and bypassing tmux results in the wrong cursor shape when switching between panes which no longer reflect the current zsh vi mode. When using ZTE compatible terminals tmux supports tracking cursor shape changes on a per pane basis using a suitable `terminal-override`, this allows zsh and vim to behave as if they are not operating in tmux and everything works as expected. However, so far I've not been able to reproduce this behaviour in iTerm2. --- zshrc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/zshrc b/zshrc index 16b09a4..00eccec 100644 --- a/zshrc +++ b/zshrc @@ -78,20 +78,19 @@ zle -N edit-command-line bindkey -M vicmd '^V' edit-command-line # Enable changing cursor shape based on vi mode -if [ "$TMUX" != "" ]; then - tmux_before="\EPtmux;\E" - tmux_after="\E\\" +if [ "$ITERM_PROFILE" != "" ]; then + # TODO: This only works outside tmux, unlike VTE compatible terminals I've + # not found a tmux terminal-override which works with iTerm2's CursorShape + # escape sequences. + # iTerm2 cursor shape escape sequences + cursor_block="\E]50;CursorShape=0\C-G" + cursor_line="\E]50;CursorShape=1\C-G" +elif [ "$(ppid_name)" != "python2" ]; then + # VTE compatible cursor shape escape sequences, excluding Guake even though + # it is VTE based it doesn't seem to handle these properly + cursor_block="\e[2 q" + cursor_line="\e[6 q" fi -if [ "$ITERM_SESSION_ID" != "" ]; then - # iterm2 cursor shape escape sequences - cursor_block="$tmux_before\E]50;CursorShape=0\C-G$tmux_after" - cursor_line="$tmux_before\E]50;CursorShape=1\C-G$tmux_after" -else - # VTE compatible cursor shape escape sequences - cursor_block="$tmux_before\E[2 q$tmux_after" - cursor_line="$tmux_before\E[6 q$tmux_after" -fi -unset tmux_before tmux_after if [[ ! -z "$cursor_block" && ! -z "$cursor_line" ]]; then # Change cursor shape when vi mode changes