From 4f26bada3175ba8b9d161d6ff2ad830b492924ce Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 9 May 2024 12:39:03 +0530 Subject: [PATCH] Fix typo in bash integration script caught by the test --- docs/shell-integration.rst | 5 ++++- shell-integration/bash/kitty.bash | 28 +++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/docs/shell-integration.rst b/docs/shell-integration.rst index bb4ac115a..103b8eefb 100644 --- a/docs/shell-integration.rst +++ b/docs/shell-integration.rst @@ -464,4 +464,7 @@ kitty also optionally supports sending the cmdline going to be executed with ``< Here, *encoded by %q* means the encoding produced by the %q format to printf in -bash and similar shells. +bash and similar shells. Which is basically shell escaping with the addition of +using `ANSI C quoting +`__ +for control characters (``$''`` quoting). diff --git a/shell-integration/bash/kitty.bash b/shell-integration/bash/kitty.bash index 9ab615429..52755fd68 100644 --- a/shell-integration/bash/kitty.bash +++ b/shell-integration/bash/kitty.bash @@ -195,19 +195,21 @@ _ksi_main() { _ksi_prompt[ps0_suffix]+="\[\e[0 q\]" # blinking default cursor fi - _ksi_get_current_command() { - builtin local last_cmd - 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 - if [[ "${_ksi_prompt[title]}" == "y" ]]; then - builtin printf "\e]2;%s%s\a" "${_ksi_prompt[hostname_prefix]@P}" "${_ksi_prompt[last_cmd]//[[:cntrl:]]}" # remove any control characters - fi - if [[ "${_ksi_prompt[mark]}" == "y" ]]; then - builtin printf "\e]133;C;cmdline=%q\a" "$last_cmd" - fi - } - if [[ "${_ksi_prompt[title]}" == "y" || "${_ksi_prompt[mark]}" ]]; then _ksi_prompt[ps0]+='$(_ksi_get_current_command)'; fi + if [[ "${_ksi_prompt[title]}" == "y" || "${_ksi_prompt[mark]}" ]]; then + _ksi_get_current_command() { + builtin local last_cmd + 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 + if [[ "${_ksi_prompt[title]}" == "y" ]]; then + builtin printf "\e]2;%s%s\a" "${_ksi_prompt[hostname_prefix]@P}" "${last_cmd//[[:cntrl:]]}" # removes any control characters + fi + if [[ "${_ksi_prompt[mark]}" == "y" ]]; then + builtin printf "\e]133;C;cmdline=%q\a" "$last_cmd" + fi + } + _ksi_prompt[ps0]+='$(_ksi_get_current_command > /dev/tty)'; + fi if [[ "${_ksi_prompt[title]}" == "y" ]]; then if [[ -z "$KITTY_PID" ]]; then