Only alias sudo if no systemwide terminfo db for xterm-kitty is found

This commit is contained in:
Kovid Goyal
2023-11-03 12:30:29 +05:30
parent a54586dfa9
commit 2aa37de6ff
3 changed files with 21 additions and 18 deletions

View File

@@ -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