From 11c03434202b36c898a78683e3802af498223337 Mon Sep 17 00:00:00 2001 From: pagedown Date: Tue, 25 Jan 2022 11:52:34 +0800 Subject: [PATCH 1/4] Add comments and minor tweaks to fish integration --- .../vendor_conf.d/kitty-shell-integration.fish | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish index 88863eb3d..f84503267 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -7,6 +7,9 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after functions --erase __ksi_schedule test -n "$KITTY_SHELL_INTEGRATION" || return 0 + # To use fish's autoloading feature, kitty prepends the vendored integration script directory to XDG_DATA_DIRS. + # The original paths needs to be restored here to not affect other programs. + # In particular, if the original XDG_DATA_DIRS does not exist, it needs to be removed. if set -q XDG_DATA_DIRS KITTY_FISH_XDG_DATA_DIR set --global --export --path XDG_DATA_DIRS "$XDG_DATA_DIRS" if set -l index (contains -i "$KITTY_FISH_XDG_DATA_DIR" $XDG_DATA_DIRS) @@ -20,10 +23,7 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after set --local _ksi (string split " " -- "$KITTY_SHELL_INTEGRATION") set --erase KITTY_SHELL_INTEGRATION KITTY_FISH_XDG_DATA_DIR - function __ksi_osc - printf "\e]%s\a" "$argv[1]" - end - + # Enable cursor shape changes for default mode and vi mode if not contains "no-cursor" $_ksi and not functions -q __ksi_set_cursor @@ -60,6 +60,7 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after end end + # Enable prompt marking with OSC 133 if not contains "no-prompt-mark" $_ksi and not set -q __ksi_prompt_state set --global __ksi_prompt_state first-run @@ -69,11 +70,11 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after end function __ksi_mark -d "Tell kitty to mark the current cursor position using OSC 133" - __ksi_osc "133;$argv[1]" + printf "\e]133;%s\a" "$argv[1]" end function __ksi_prompt_start - # preserve the command exit code from $status + # Preserve the command exit code from $status set --local cmd_status $status if contains "$__ksi_prompt_state" post-exec first-run __ksi_mark D @@ -100,7 +101,7 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after functions -c fish_prompt __ksi_original_fish_prompt if __ksi_function_is_not_empty fish_mode_prompt - # see https://github.com/starship/starship/issues/1283 + # See https://github.com/starship/starship/issues/1283 # for why we have to test for a non-empty fish_mode_prompt functions -c fish_mode_prompt __ksi_original_fish_mode_prompt function fish_mode_prompt @@ -126,7 +127,7 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after set --global __ksi_prompt_state post-exec __ksi_mark "D;$status" end - # with prompt marking kitty clears the current prompt on resize so we need + # With prompt marking kitty clears the current prompt on resize so we need # fish to redraw it set --global fish_handle_reflow 1 From 5d4b0c0befede126e5997bd88b111a40a8471f3b Mon Sep 17 00:00:00 2001 From: pagedown Date: Tue, 25 Jan 2022 13:01:54 +0800 Subject: [PATCH 2/4] Set the pre-exec cursor shape in fish vi mode and config on demand --- .../kitty-shell-integration.fish | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish index f84503267..ab0ecfc91 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -27,37 +27,41 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after if not contains "no-cursor" $_ksi and not functions -q __ksi_set_cursor - function __ksi_set_cursor --on-variable fish_key_bindings -d "Set cursor shape for fish default mode" - if test "$fish_key_bindings" = fish_default_key_bindings - not functions -q __ksi_bar_cursor __ksi_block_cursor || return + function __ksi_block_cursor --on-event fish_preexec -d "Set cursor shape to steady block before executing command" + printf "\e[2 q" + end - function __ksi_bar_cursor --on-event fish_prompt + function __ksi_set_cursor --on-variable fish_key_bindings -d "Set the cursor shape for different modes when switching key bindings" + if test "$fish_key_bindings" = fish_default_key_bindings + not functions -q __ksi_bar_cursor || return + function __ksi_bar_cursor --on-event fish_prompt -d "Set cursor shape to blinking bar on prompt" printf "\e[5 q" end - - function __ksi_block_cursor --on-event fish_preexec - printf "\e[2 q" - end else - functions --erase __ksi_bar_cursor __ksi_block_cursor + functions --erase __ksi_bar_cursor + contains "$fish_key_bindings" fish_vi_key_bindings fish_hybrid_key_bindings + and __ksi_set_vi_cursor end end - __ksi_set_cursor - functions -q __ksi_bar_cursor - and __ksi_bar_cursor - # Set the vi mode cursor shapes only when none of them are configured - set --local vi_modes fish_cursor_{default,insert,replace_one,visual} - set --local vi_cursor_shapes block line underscore block - set -q $vi_modes - if test "$status" -eq 4 + function __ksi_set_vi_cursor -d "Set the vi mode cursor shapes" + # Set the vi mode cursor shapes only when none of them are configured + set --local vi_modes fish_cursor_{default,insert,replace_one,visual} + set -q $vi_modes + test "$status" -eq 4 || return + + set --local vi_cursor_shapes block line underscore block for i in 1 2 3 4 set --global $vi_modes[$i] $vi_cursor_shapes[$i] blink end - # Change the vi mode cursor shape on the first run - contains "$fish_key_bindings" fish_vi_key_bindings fish_hybrid_key_bindings - and test "$fish_bind_mode" = "insert" && printf "\e[5 q" || printf "\e[1 q" + + # Change the cursor shape for current mode + test "$fish_bind_mode" = "insert" && printf "\e[5 q" || printf "\e[1 q" end + + __ksi_set_cursor + functions -q __ksi_bar_cursor + and __ksi_bar_cursor end # Enable prompt marking with OSC 133 From 3aec573d40701a1ab7b540c9092a465b5825afbe Mon Sep 17 00:00:00 2001 From: pagedown Date: Tue, 25 Jan 2022 13:58:11 +0800 Subject: [PATCH 3/4] Use blinking block for commands consistent with zsh and bash integration --- .../fish/vendor_conf.d/kitty-shell-integration.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish index ab0ecfc91..86b5fe364 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -27,8 +27,8 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after if not contains "no-cursor" $_ksi and not functions -q __ksi_set_cursor - function __ksi_block_cursor --on-event fish_preexec -d "Set cursor shape to steady block before executing command" - printf "\e[2 q" + function __ksi_block_cursor --on-event fish_preexec -d "Set cursor shape to blinking block before executing command" + printf "\e[1 q" end function __ksi_set_cursor --on-variable fish_key_bindings -d "Set the cursor shape for different modes when switching key bindings" From a47b3bf5786491d3c90e6b989003fad4f40a65cf Mon Sep 17 00:00:00 2001 From: pagedown Date: Tue, 25 Jan 2022 14:00:28 +0800 Subject: [PATCH 4/4] Fix the blinking block cursor shape for commands in bash integration --- shell-integration/bash/kitty.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 3746aeef4..9f4ec198b 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -61,7 +61,7 @@ _ksi_main() { if [[ "${_ksi_prompt[cursor]}" == "y" ]]; then _ksi_prompt[ps1]+="\[\e[5 q\]" # blinking bar cursor - _ksi_prompt[ps0]+="\[\e[5 q\]" # blinking block cursor + _ksi_prompt[ps0]+="\[\e[1 q\]" # blinking block cursor fi if [[ "${_ksi_prompt[title]}" == "y" ]]; then