diff --git a/docs/changelog.rst b/docs/changelog.rst index dc099d75b..e48bb6cc7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -46,6 +46,8 @@ Detailed list of changes 0.30.1 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Shell integration: Automatically alias sudo to make the kitty terminfo files available in the sudo environment. Can be turned off via :opt:`shell_integration` + - ssh kitten: Fix a regression in 0.28.0 that caused using ``--kitten`` to override :file:`ssh.conf` not inheriting settings from :file:`ssh.conf` (:iss:`6639`) diff --git a/docs/shell-integration.rst b/docs/shell-integration.rst index 06edac11d..1e8a2ebca 100644 --- a/docs/shell-integration.rst +++ b/docs/shell-integration.rst @@ -91,6 +91,10 @@ no-complete Note that for the fish shell this does not take effect, since fish already comes with a kitty completion script. +no-sudo + Do not alias :program:`sudo` to ensure the kitty terminfo files are + available in the sudo environment + More ways to browse command output ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/kitty/options/definition.py b/kitty/options/definition.py index c37ddeb02..69d220d93 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -3028,7 +3028,7 @@ jumping to previous prompts, browsing the output of the previous command in a pager, etc. on supported shells. Set to :code:`disabled` to turn off shell integration, completely. It is also possible to disable individual features, set to a space separated list of these values: :code:`no-rc`, :code:`no-cursor`, -:code:`no-title`, :code:`no-cwd`, :code:`no-prompt-mark`, :code:`no-complete`. +:code:`no-title`, :code:`no-cwd`, :code:`no-prompt-mark`, :code:`no-complete`, :code:`no-sudo`. See :ref:`Shell integration ` for details. ''' ) diff --git a/kitty/options/utils.py b/kitty/options/utils.py index 2f8bda5bf..0beec1db1 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -863,7 +863,7 @@ def store_multiple(val: str, current_val: Container[str]) -> Iterable[Tuple[str, yield val, val -allowed_shell_integration_values = frozenset({'enabled', 'disabled', 'no-rc', 'no-cursor', 'no-title', 'no-prompt-mark', 'no-complete', 'no-cwd'}) +allowed_shell_integration_values = frozenset({'enabled', 'disabled', 'no-rc', 'no-cursor', 'no-title', 'no-prompt-mark', 'no-complete', 'no-cwd', 'no-sudo'}) def shell_integration(x: str) -> FrozenSet[str]: diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 621ca90f9..d42477a94 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -75,7 +75,7 @@ fi # which is not available on older bash builtin declare -A _ksi_prompt _ksi_prompt=( - [cursor]='y' [title]='y' [mark]='y' [complete]='y' [cwd]='y' [ps0]='' [ps0_suffix]='' [ps1]='' [ps1_suffix]='' [ps2]='' + [cursor]='y' [title]='y' [mark]='y' [complete]='y' [cwd]='y' [sudo]='y' [ps0]='' [ps0_suffix]='' [ps1]='' [ps1_suffix]='' [ps2]='' [hostname_prefix]='' [sourced]='y' [last_reported_cwd]='' ) @@ -89,6 +89,7 @@ _ksi_main() { "no-prompt-mark") _ksi_prompt[mark]='n';; "no-complete") _ksi_prompt[complete]='n';; "no-cwd") _ksi_prompt[cwd]='n';; + "no-sudo") _ksi_prompt[sudo]='n';; esac done IFS="$ifs" @@ -211,6 +212,11 @@ _ksi_main() { builtin alias edit-in-kitty="kitten edit-in-kitty" + if [[ "${_ksi_prompt[sudo]}" == "y" ]]; then + # Ensure terminfo is available in sudo + [[ -n "$TERMINFO" ]] && builtin alias sudo="sudo TERMINFO=\"$TERMINFO\"" + fi + if [[ "${_ksi_prompt[complete]}" == "y" ]]; then _ksi_completions() { builtin local src 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 bcee42abd..587dd5a57 100644 --- a/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish +++ b/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish @@ -108,6 +108,13 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after __update_cwd_osc end + if not contains "no-sudo" $_ksi + # Ensure terminfo is available in sudo + if test -n "$TERMINFO" + alias sudo="sudo TERMINFO=\"$TERMINFO\"" + end + end + # Handle clone launches if test -n "$KITTY_IS_CLONE_LAUNCH" set --local orig_conda_env "$CONDA_DEFAULT_ENV" diff --git a/shell-integration/zsh/kitty-integration b/shell-integration/zsh/kitty-integration index 84d288267..e0e7e4bb3 100644 --- a/shell-integration/zsh/kitty-integration +++ b/shell-integration/zsh/kitty-integration @@ -84,7 +84,7 @@ precmd_functions+=(_ksi_deferred_init) _ksi_deferred_init() { builtin emulate -L zsh -o no_warn_create_global -o no_aliases - # Recognized options: no-cursor, no-title, no-prompt-mark, no-complete, no-cwd. + # Recognized options: no-cursor, no-title, no-prompt-mark, no-complete, no-cwd, no-sudo. builtin local -a opt opt=(${(s: :)KITTY_SHELL_INTEGRATION}) builtin unset KITTY_SHELL_INTEGRATION @@ -388,6 +388,11 @@ _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\"" + fi + # Map alt+left/right to move by word if not already mapped. This is expected behavior on macOS and I am tired # of answering questions about it. [[ $(builtin bindkey "^[[1;3C") == *" undefined-key" ]] && builtin bindkey "^[[1;3C" "forward-word"