More efficient encoding for cmdline in the prompt marking escape code

This commit is contained in:
Kovid Goyal 2024-05-09 12:03:02 +05:30
parent 1e528fd299
commit 219e53826b
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
5 changed files with 10 additions and 12 deletions

View file

@ -204,9 +204,7 @@ _ksi_main() {
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="
for (( i=0; i<${#last_cmd}; i++ )); do builtin printf '%x ' "'${last_cmd:$i:1}"; done
builtin printf "\a"
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

View file

@ -215,9 +215,7 @@ _ksi_deferred_init() {
# its preexec hook before us, we'll incorrectly mark its output as
# belonging to the command (as if the user typed it into zle) rather
# than command output.
builtin print -nu "$_ksi_fd" '\e]133;C;cmdline='
for (( i=0; i<${#1}; i++ )); do builtin print -nu "$_ksi_fd" -f '%x ' "'${1:$i:1}"; done
builtin print -nu "$_ksi_fd" '\a'
builtin print -nu "$_ksi_fd" -f '\e]133;C;cmdline=%q\a' "$1"
(( _ksi_state = 1 ))
}