From 492ec3dfbf3be6f27603baabb5c2844f91436e04 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 Oct 2023 12:20:59 +0530 Subject: [PATCH] zsh integration: Use a function for sudo This fixes sudo --edit and works around the zsh sudo completions bug: https://www.zsh.org/mla/workers/2023/msg00983.html --- shell-integration/zsh/kitty-integration | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/shell-integration/zsh/kitty-integration b/shell-integration/zsh/kitty-integration index 2b22a1a0f..dde6c5b0e 100644 --- a/shell-integration/zsh/kitty-integration +++ b/shell-integration/zsh/kitty-integration @@ -389,8 +389,22 @@ _ksi_deferred_init() { builtin alias edit-in-kitty="kitten edit-in-kitty" if (( ! opt[(Ie)no-sudo] )); then - # Ensure terminfo is available in sudo - [[ -n "$TERMINFO" ]] && builtin alias sudo="sudo TERMINFO=\"$TERMINFO\"" + 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 [[ -z "$TERMINFO" || "$is_sudoedit" == "y" ]]; then + builtin command sudo "$@"; + else + builtin command sudo TERMINFO="$TERMINFO" "$@"; + fi + } fi # Map alt+left/right to move by word if not already mapped. This is expected behavior on macOS and I am tired