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
This commit is contained in:
Kovid Goyal
2023-10-31 12:20:59 +05:30
parent 309a6e9319
commit 492ec3dfbf

View File

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