From 0b2837fcfa8dd01c3779666a50c66865279feb88 Mon Sep 17 00:00:00 2001 From: pagedown Date: Mon, 7 Mar 2022 20:43:14 +0800 Subject: [PATCH 1/4] Fix bash integration debug log printing --- shell-integration/bash/kitty.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index b50e48c25..0e006c066 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -89,7 +89,7 @@ _ksi_main() { # print a line to STDOUT of parent kitty process builtin local b b=$(builtin command base64 <<< "${@}") - builtin printf "\eP@kitty-print|%s\e\\" "${b//\\n}" + builtin printf "\eP@kitty-print|%s\e\\" "${b//[[:space:]]}}" } _ksi_set_mark() { From b4b0bdc85331ed7342caeb969caa3151de0a928c Mon Sep 17 00:00:00 2001 From: pagedown Date: Mon, 7 Mar 2022 20:49:18 +0800 Subject: [PATCH 2/4] DCS @ kitty-print should be output to STDERR --- shell-integration/bash/kitty.bash | 2 +- shell-integration/zsh/kitty-integration | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 0e006c066..3daae7a27 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -86,7 +86,7 @@ _ksi_main() { builtin unset KITTY_SHELL_INTEGRATION _ksi_debug_print() { - # print a line to STDOUT of parent kitty process + # print a line to STDERR of parent kitty process builtin local b b=$(builtin command base64 <<< "${@}") builtin printf "\eP@kitty-print|%s\e\\" "${b//[[:space:]]}}" diff --git a/shell-integration/zsh/kitty-integration b/shell-integration/zsh/kitty-integration index 131a9b072..878efb0f3 100644 --- a/shell-integration/zsh/kitty-integration +++ b/shell-integration/zsh/kitty-integration @@ -61,7 +61,7 @@ typeset -gi _ksi_fd } } 2>/dev/null || (( _ksi_fd = 1 )) -# Asks kitty to print $@ to its STDOUT. This is for debugging. +# Asks kitty to print $@ to its STDERR. This is for debugging. _ksi_debug_print() { builtin local data data=$(builtin command base64 <<<"${(j: :)@}") || builtin return From cf0cd9acd968369590c9f07308fd0f292d9a7f09 Mon Sep 17 00:00:00 2001 From: pagedown Date: Mon, 7 Mar 2022 20:53:35 +0800 Subject: [PATCH 3/4] Remove trailing semicolons --- shell-integration/bash/kitty.bash | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 3daae7a27..3aea07ed4 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -8,32 +8,32 @@ _ksi_inject() { if [[ -n "$KITTY_BASH_INJECT" ]]; then builtin local kitty_bash_inject="$KITTY_BASH_INJECT" builtin unset KITTY_BASH_INJECT - builtin unset ENV; + builtin unset ENV if [[ -z "$HOME" ]]; then HOME=~; fi if [[ -z "$KITTY_BASH_ETC_LOCATION" ]]; then KITTY_BASH_ETC_LOCATION="/etc"; fi _ksi_safe_source() { if [[ -f "$1" && -r "$1" ]]; then - builtin source "$1"; - builtin return 0; + builtin source "$1" + builtin return 0 fi - builtin return 1; + builtin return 1 } if [[ "$kitty_bash_inject" == *"posix"* ]]; then - _ksi_safe_source "$KITTY_BASH_POSIX_ENV" && builtin export ENV="$KITTY_BASH_POSIX_ENV"; + _ksi_safe_source "$KITTY_BASH_POSIX_ENV" && builtin export ENV="$KITTY_BASH_POSIX_ENV" else - builtin set +o posix; + builtin set +o posix if [[ -n "$KITTY_BASH_UNEXPORT_HISTFILE" ]]; then - builtin export -n HISTFILE; - builtin unset KITTY_BASH_UNEXPORT_HISTFILE; + builtin export -n HISTFILE + builtin unset KITTY_BASH_UNEXPORT_HISTFILE fi # See run_startup_files() in shell.c in the Bash source code if builtin shopt -q login_shell; then if [[ "$kitty_bash_inject" != *"no-profile"* ]]; then - _ksi_safe_source "$KITTY_BASH_ETC_LOCATION/profile"; - _ksi_safe_source "$HOME/.bash_profile" || _ksi_safe_source "$HOME/.bash_login" || _ksi_safe_source "$HOME/.profile"; + _ksi_safe_source "$KITTY_BASH_ETC_LOCATION/profile" + _ksi_safe_source "$HOME/.bash_profile" || _ksi_safe_source "$HOME/.bash_login" || _ksi_safe_source "$HOME/.profile" fi else if [[ "$kitty_bash_inject" != *"no-rc"* ]]; then @@ -42,13 +42,13 @@ _ksi_inject() { _ksi_safe_source "$KITTY_BASH_ETC_LOCATION/bash.bashrc" # Arch, Debian, Ubuntu # Fedora uses /etc/bashrc sourced from ~/.bashrc instead of SYS_BASHRC if [[ -z "$KITTY_BASH_RCFILE" ]]; then KITTY_BASH_RCFILE="$HOME/.bashrc"; fi - _ksi_safe_source "$KITTY_BASH_RCFILE"; + _ksi_safe_source "$KITTY_BASH_RCFILE" fi fi fi - builtin unset KITTY_BASH_RCFILE; - builtin unset KITTY_BASH_POSIX_ENV; - builtin unset KITTY_BASH_ETC_LOCATION; + builtin unset KITTY_BASH_RCFILE + builtin unset KITTY_BASH_POSIX_ENV + builtin unset KITTY_BASH_ETC_LOCATION builtin unset -f _ksi_safe_source fi } @@ -57,14 +57,14 @@ builtin unset -f _ksi_inject if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then builtin unset KITTY_SHELL_INTEGRATION - builtin printf "%s\n" "Bash version ${BASH_VERSION} too old, kitty shell integration disabled" > /dev/stderr; - builtin return; + builtin printf "%s\n" "Bash version ${BASH_VERSION} too old, kitty shell integration disabled" > /dev/stderr + builtin return fi if [[ "${_ksi_prompt[sourced]}" == "y" ]]; then # we have already run builtin unset KITTY_SHELL_INTEGRATION - builtin return; + builtin return fi # this is defined outside _ksi_main to make it global without using declare -g @@ -135,7 +135,7 @@ _ksi_main() { # the first part removes everything from the last \n onwards # the second part appends a newline with the secondary marking # the third part appends everything after the last newline - PS1=${PS1%@('\n'|$'\n')*}${_ksi_prompt[secondary_prompt]}${PS1##*@('\n'|$'\n')}; + PS1=${PS1%@('\n'|$'\n')*}${_ksi_prompt[secondary_prompt]}${PS1##*@('\n'|$'\n')} builtin eval "$oldval" fi PS1="${_ksi_prompt[ps1]}$PS1" @@ -159,13 +159,13 @@ _ksi_main() { if [[ -n "$SSH_TTY" || -n "$SSH2_TTY$KITTY_WINDOW_ID" ]]; then # connected to most SSH servers # or use ssh kitten to connected to some SSH servers that do not set SSH_TTY - _ksi_prompt[hostname_prefix]="\h: "; + _ksi_prompt[hostname_prefix]="\h: " else if [[ -n "$(builtin command -v who)" && "$(builtin command who -m 2> /dev/null)" =~ "\([a-fA-F.:0-9]+\)$" ]]; then # the shell integration script is installed manually on the remote system # the environment variables are cleared after sudo # OpenSSH's sshd creates entries in utmp for every login so use those - _ksi_prompt[hostname_prefix]="\h: "; + _ksi_prompt[hostname_prefix]="\h: " fi fi fi From 4aea64261eb1f783cde4e30e7d2934bd0114f71b Mon Sep 17 00:00:00 2001 From: pagedown Date: Mon, 7 Mar 2022 20:56:02 +0800 Subject: [PATCH 4/4] ... --- shell-integration/bash/kitty.bash | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 3aea07ed4..ca8b89d71 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -160,13 +160,11 @@ _ksi_main() { # connected to most SSH servers # or use ssh kitten to connected to some SSH servers that do not set SSH_TTY _ksi_prompt[hostname_prefix]="\h: " - else - if [[ -n "$(builtin command -v who)" && "$(builtin command who -m 2> /dev/null)" =~ "\([a-fA-F.:0-9]+\)$" ]]; then - # the shell integration script is installed manually on the remote system - # the environment variables are cleared after sudo - # OpenSSH's sshd creates entries in utmp for every login so use those - _ksi_prompt[hostname_prefix]="\h: " - fi + elif [[ -n "$(builtin command -v who)" && "$(builtin command who -m 2> /dev/null)" =~ "\([a-fA-F.:0-9]+\)$" ]]; then + # the shell integration script is installed manually on the remote system + # the environment variables are cleared after sudo + # OpenSSH's sshd creates entries in utmp for every login so use those + _ksi_prompt[hostname_prefix]="\h: " fi fi # see https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html#Controlling-the-Prompt