From 393425e3d1da3a95c1d04625d15f19d3feeb8aee Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 23 Feb 2022 13:59:39 +0800 Subject: [PATCH 1/5] Remove trailing spaces --- shell-integration/bash/kitty.bash | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 466cee7b0..392bdd17b 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -21,14 +21,14 @@ _ksi_main() { _ksi_debug_print() { # print a line to STDOUT of parent kitty process builtin local b=$(command base64 <<< "${@}" | tr -d \\n) - builtin printf "\eP@kitty-print|%s\e\\" "$b" + builtin printf "\eP@kitty-print|%s\e\\" "$b" # " } _ksi_safe_source() { - if [[ -f "$1" && -r "$1" ]]; then - builtin source "$1"; - builtin return 0; + if [[ -f "$1" && -r "$1" ]]; then + builtin source "$1"; + builtin return 0; fi builtin return 1; } @@ -37,15 +37,15 @@ _ksi_main() { builtin unset ENV; if [[ -z "$HOME" ]]; then HOME=~; fi if [[ -z "$KITTY_BASH_ETC_LOCATION" ]]; then KITTY_BASH_ETC_LOCATION="/etc"; fi - if [[ "$KITTY_BASH_INJECT" == *"posix"* ]]; then + if [[ "$KITTY_BASH_INJECT" == *"posix"* ]]; then _ksi_safe_source "$KITTY_BASH_POSIX_ENV" && builtin export ENV="$KITTY_BASH_POSIX_ENV"; else - set +o posix; + set +o posix; # 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 "$HOME/.bash_profile" || _ksi_safe_source "$HOME/.bash_login" || _ksi_safe_source "$HOME/.profile"; fi else if [[ "$KITTY_BASH_INJECT" != *"no-rc"* ]]; then @@ -65,8 +65,8 @@ _ksi_main() { fi builtin unset -f _ksi_safe_source - _ksi_set_mark() { - _ksi_prompt["${1}_mark"]="\[\e]133;k;${1}_kitty\a\]" + _ksi_set_mark() { + _ksi_prompt["${1}_mark"]="\[\e]133;k;${1}_kitty\a\]" } _ksi_set_mark start @@ -105,7 +105,7 @@ _ksi_main() { # mark the last line as a secondary prompt. Otherwise on resize the # lines before the last line will be erased by kitty. # the first part removes everything from the last \n onwards - # the second part appends a newline with the secondary marking + # 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')}; eval "$oldval" @@ -121,12 +121,12 @@ _ksi_main() { fi } - if [[ "${_ksi_prompt[cursor]}" == "y" ]]; then + if [[ "${_ksi_prompt[cursor]}" == "y" ]]; then _ksi_prompt[ps1_suffix]+="\[\e[5 q\]" # blinking bar cursor _ksi_prompt[ps0_suffix]+="\[\e[0 q\]" # blinking default cursor fi - if [[ "${_ksi_prompt[title]}" == "y" ]]; then + if [[ "${_ksi_prompt[title]}" == "y" ]]; then # see https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html#Controlling-the-Prompt # we use suffix here because some distros add title setting to their bashrc files by default _ksi_prompt[ps1_suffix]+="\[\e]2;\w\a\]" @@ -142,13 +142,13 @@ _ksi_main() { _ksi_prompt[ps0_suffix]+='$(_ksi_get_current_command)' fi - if [[ "${_ksi_prompt[mark]}" == "y" ]]; then + if [[ "${_ksi_prompt[mark]}" == "y" ]]; then _ksi_prompt[ps1]+="\[\e]133;A\a\]" _ksi_prompt[ps2]+="\[\e]133;A;k=s\a\]" _ksi_prompt[ps0]+="\[\e]133;C\a\]" fi - if [[ "${_ksi_prompt[complete]}" == "y" ]]; then + if [[ "${_ksi_prompt[complete]}" == "y" ]]; then _ksi_completions() { builtin local src builtin local limit @@ -164,19 +164,19 @@ _ksi_main() { # wrap our prompt additions in markers we can use to remove them using # bash's anemic pattern substitution - if [[ -n "${_ksi_prompt[ps0]}" ]]; then + if [[ -n "${_ksi_prompt[ps0]}" ]]; then _ksi_prompt[ps0]="${_ksi_prompt[start_mark]}${_ksi_prompt[ps0]}${_ksi_prompt[end_mark]}" fi - if [[ -n "${_ksi_prompt[ps0_suffix]}" ]]; then + if [[ -n "${_ksi_prompt[ps0_suffix]}" ]]; then _ksi_prompt[ps0_suffix]="${_ksi_prompt[start_suffix_mark]}${_ksi_prompt[ps0_suffix]}${_ksi_prompt[end_suffix_mark]}" fi - if [[ -n "${_ksi_prompt[ps1]}" ]]; then + if [[ -n "${_ksi_prompt[ps1]}" ]]; then _ksi_prompt[ps1]="${_ksi_prompt[start_mark]}${_ksi_prompt[ps1]}${_ksi_prompt[end_mark]}" fi - if [[ -n "${_ksi_prompt[ps1_suffix]}" ]]; then + if [[ -n "${_ksi_prompt[ps1_suffix]}" ]]; then _ksi_prompt[ps1_suffix]="${_ksi_prompt[start_suffix_mark]}${_ksi_prompt[ps1_suffix]}${_ksi_prompt[end_suffix_mark]}" fi - if [[ -n "${_ksi_prompt[ps2]}" ]]; then + if [[ -n "${_ksi_prompt[ps2]}" ]]; then _ksi_prompt[ps2]="${_ksi_prompt[start_mark]}${_ksi_prompt[ps2]}${_ksi_prompt[end_mark]}" fi builtin unset _ksi_prompt[start_mark] From e0c84c7176e5750f9169f12930d6ca7153381f06 Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 23 Feb 2022 14:01:47 +0800 Subject: [PATCH 2/5] Use bash builtin --- shell-integration/bash/kitty.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 392bdd17b..6b2be52dd 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -20,7 +20,7 @@ _ksi_main() { _ksi_debug_print() { # print a line to STDOUT of parent kitty process - builtin local b=$(command base64 <<< "${@}" | tr -d \\n) + builtin local b=$(builtin command base64 <<< "${@}" | tr -d \\n) builtin printf "\eP@kitty-print|%s\e\\" "$b" # " } @@ -40,7 +40,7 @@ _ksi_main() { if [[ "$KITTY_BASH_INJECT" == *"posix"* ]]; then _ksi_safe_source "$KITTY_BASH_POSIX_ENV" && builtin export ENV="$KITTY_BASH_POSIX_ENV"; else - set +o posix; + builtin set +o posix; # 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 @@ -99,7 +99,7 @@ _ksi_main() { fi if [[ -n "${_ksi_prompt[ps1]}" ]]; then if [[ "${_ksi_prompt[mark]}" == "y" && ( "${PS1}" == *"\n"* || "${PS1}" == *$'\n'* ) ]]; then - local oldval=$(builtin shopt -p extglob) + builtin local oldval=$(builtin shopt -p extglob) builtin shopt -s extglob # bash does not redraw the leading lines in a multiline prompt so # mark the last line as a secondary prompt. Otherwise on resize the @@ -108,7 +108,7 @@ _ksi_main() { # 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')}; - eval "$oldval" + builtin eval "$oldval" fi PS1="${_ksi_prompt[ps1]}$PS1" fi @@ -134,7 +134,7 @@ _ksi_main() { _ksi_debug_print "ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command in window title will not be robust" fi _ksi_get_current_command() { - local last_cmd=$(HISTTIMEFORMAT= builtin history 1) + builtin local last_cmd=$(HISTTIMEFORMAT= builtin history 1) last_cmd="${last_cmd#*[[:digit:]]*[[:space:]]}" # remove leading history number last_cmd="${last_cmd#"${last_cmd%%[![:space:]]*}"}" # remove remaining leading whitespace builtin printf "\e]2;%s\a" "${last_cmd}" @@ -154,7 +154,7 @@ _ksi_main() { builtin local limit # Send all words up to the word the cursor is currently on builtin let limit=1+$COMP_CWORD - src=$(builtin printf "%s\n" "${COMP_WORDS[@]:0:$limit}" | command kitty +complete bash) + src=$(builtin printf "%s\n" "${COMP_WORDS[@]:0:$limit}" | builtin command kitty +complete bash) if [[ $? == 0 ]]; then builtin eval ${src} fi From 741ef7f1152806a60952b368586d1dc4ed783be8 Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 23 Feb 2022 14:09:13 +0800 Subject: [PATCH 3/5] Remove new lines with bash --- shell-integration/bash/kitty.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 6b2be52dd..e72ea2e41 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -20,8 +20,8 @@ _ksi_main() { _ksi_debug_print() { # print a line to STDOUT of parent kitty process - builtin local b=$(builtin command base64 <<< "${@}" | tr -d \\n) - builtin printf "\eP@kitty-print|%s\e\\" "$b" + builtin local b=$(builtin command base64 <<< "${@}") + builtin printf "\eP@kitty-print|%s\e\\" "${b//\\n}" # " } From 3d7b3f7d7214419cb778cd98f923847cdbaa5fcb Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 23 Feb 2022 14:21:13 +0800 Subject: [PATCH 4/5] Use the official project name of Bash --- docs/changelog.rst | 2 +- shell-integration/bash/kitty.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 97b0e3ff5..a67b49d53 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -78,7 +78,7 @@ Detailed list of changes 0.24.3 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- BASH integration: No longer modify :file:`~/.bashrc` to load :ref:`shell integration `. +- Bash integration: No longer modify :file:`~/.bashrc` to load :ref:`shell integration `. It is recommended to remove the lines used to load the shell integration from :file:`~/.bashrc` as they are no-ops. - macOS: Allow kitty to handle various URL types. Can be configured via diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index e72ea2e41..b940bd193 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -41,7 +41,7 @@ _ksi_main() { _ksi_safe_source "$KITTY_BASH_POSIX_ENV" && builtin export ENV="$KITTY_BASH_POSIX_ENV"; else builtin set +o posix; - # See run_startup_files() in shell.c in the BASH source code + # 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"; From 444a690a865ad8bae5d74e780901a592905c4818 Mon Sep 17 00:00:00 2001 From: pagedown Date: Wed, 23 Feb 2022 14:37:45 +0800 Subject: [PATCH 5/5] Remove the extra comment line --- shell-integration/bash/kitty.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index b940bd193..41a35a2e6 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -22,7 +22,6 @@ _ksi_main() { # print a line to STDOUT of parent kitty process builtin local b=$(builtin command base64 <<< "${@}") builtin printf "\eP@kitty-print|%s\e\\" "${b//\\n}" - # " } _ksi_safe_source() {