From 2aa37de6ffcdd869402283682589b0f405a5f64f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 3 Nov 2023 12:30:29 +0530 Subject: [PATCH] Only alias sudo if no systemwide terminfo db for xterm-kitty is found --- shell-integration/bash/kitty.bash | 4 +-- .../kitty-shell-integration.fish | 1 + shell-integration/zsh/kitty-integration | 34 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 983275448..ec9584a26 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -16,7 +16,7 @@ if [[ -n "$KITTY_BASH_INJECT" ]]; then [[ -f "$1" && -r "$1" ]] && builtin return 0; builtin return 1; } - if [[ -n "$ksi_val" && "$ksi_val" != *no-sudo* ]]; then + if [[ -n "$ksi_val" && "$ksi_val" != *no-sudo* && -n "$TERMINFO" && ! ( -r "/usr/share/terminfo/x/xterm-kitty" || -r "/usr/share/terminfo/78/xterm-kitty" ) ]]; then # this must be done before sourcing user bashrc otherwise aliasing of sudo does not work sudo() { # Ensure terminfo is available in sudo @@ -28,7 +28,7 @@ if [[ -n "$KITTY_BASH_INJECT" ]]; then fi [[ "$arg" != -* && "$arg" != *=* ]] && builtin break # command found done - if [[ -z "$TERMINFO" || "$is_sudoedit" == "y" ]]; then + if [[ "$is_sudoedit" == "y" ]]; then builtin command sudo "$@"; else builtin command sudo TERMINFO="$TERMINFO" "$@"; 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 07db663f5..77fc837c4 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -112,6 +112,7 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after # for sudo it will be clobbered by us, so only install this if sudo is not already function if not contains "no-sudo" $_ksi and test -n "$TERMINFO" -a "file" = (type -t sudo) + and not test -r "/usr/share/terminfo/x/xterm-kitty" -o -r "/usr/share/terminfo/78/xterm-kitty" # Ensure terminfo is available in sudo function sudo set --local is_sudoedit "n" diff --git a/shell-integration/zsh/kitty-integration b/shell-integration/zsh/kitty-integration index dde6c5b0e..c66b6c807 100644 --- a/shell-integration/zsh/kitty-integration +++ b/shell-integration/zsh/kitty-integration @@ -388,23 +388,25 @@ _ksi_deferred_init() { builtin alias edit-in-kitty="kitten edit-in-kitty" - if (( ! opt[(Ie)no-sudo] )); then - sudo() { - # Ensure terminfo is available in sudo - builtin local is_sudoedit="n" - for arg; do - if [[ "$arg" == "-e" || $arg == "--edit" ]]; then - is_sudoedit="y" - builtin break; + if (( ! opt[(Ie)no-sudo] )) ; then + if [[ -n "$TERMINFO" && ! ( -r "/usr/share/terminfo/x/xterm-kitty" || -r "/usr/share/terminfo/78/xterm-kitty" ) ]]; then + sudo() { + # Ensure terminfo is available in sudo + builtin local is_sudoedit="n" + for arg; do + if [[ "$arg" == "-e" || $arg == "--edit" ]]; then + is_sudoedit="y" + builtin break; + fi + [[ "$arg" != -* && "$arg" != *=* ]] && builtin break # command found + done + if [[ "$is_sudoedit" == "y" ]]; then + builtin command sudo "$@"; + else + builtin command sudo TERMINFO="$TERMINFO" "$@"; fi - [[ "$arg" != -* && "$arg" != *=* ]] && builtin break # command found - done - if [[ -z "$TERMINFO" || "$is_sudoedit" == "y" ]]; then - builtin command sudo "$@"; - else - builtin command sudo TERMINFO="$TERMINFO" "$@"; - fi - } + } + fi fi # Map alt+left/right to move by word if not already mapped. This is expected behavior on macOS and I am tired