strip kitty markup from ps1 before checking for newlines

This commit is contained in:
Kovid Goyal 2022-02-22 11:40:09 +05:30
parent 2d2f4b9ba9
commit 05617f7dca
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -49,22 +49,27 @@ _ksi_main() {
PS0=${PS0//\\\[\\e\]133;k;start_suffix_kitty\\a\\\]*end_suffix_kitty\\a\\\]} PS0=${PS0//\\\[\\e\]133;k;start_suffix_kitty\\a\\\]*end_suffix_kitty\\a\\\]}
PS0="${PS0}${_ksi_prompt[ps0_suffix]}" PS0="${PS0}${_ksi_prompt[ps0_suffix]}"
fi fi
# restore PS1 to its pristine state without our additions
if [[ -n "${_ksi_prompt[ps1]}" ]]; then if [[ -n "${_ksi_prompt[ps1]}" ]]; then
PS1=${PS1//\\\[\\e\]133;k;start_kitty\\a\\\]*end_kitty\\a\\\]} PS1=${PS1//\\\[\\e\]133;k;start_kitty\\a\\\]*end_kitty\\a\\\]}
PS1="${_ksi_prompt[ps1]}$PS1" PS1=${PS1//\\\[\\e\]133;k;start_secondary_kitty\\a\\\]*end_secondary_kitty\\a\\\]}
if [[ "${_ksi_prompt[mark]}" == "y" && "${PS1}" == *$'\n'* ]]; then fi
if [[ -n "${_ksi_prompt[ps1_suffix]}" ]]; then
PS1=${PS1//\\\[\\e\]133;k;start_suffix_kitty\\a\\\]*end_suffix_kitty\\a\\\]}
fi
if [[ -n "${_ksi_prompt[ps1]}" ]]; then
if [[ "${_ksi_prompt[mark]}" == "y" && "${PS1}" == *"\n"* ]]; then
# bash does not redraw the leading lines in a multiline prompt so # bash does not redraw the leading lines in a multiline prompt so
# mark the last line as a secondary prompt. Otherwise on resize the # mark the last line as a secondary prompt. Otherwise on resize the
# lines before the last line will be erased by kitty. # lines before the last line will be erased by kitty.
PS1=${PS1//\\\[\\e\]133;k;start_secondary_kitty\\a\\\]*end_secondary_kitty\\a\\\]}
# the first part removes everything from the last \n onwards # 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 # the third part appends everything after the last newline
PS1=${PS1%'\n'*}${_ksi_prompt[secondary_prompt]}${PS1##*'\n'} PS1=${PS1%'\n'*}${_ksi_prompt[secondary_prompt]}${PS1##*'\n'}
fi fi
PS1="${_ksi_prompt[ps1]}$PS1"
fi fi
if [[ -n "${_ksi_prompt[ps1_suffix]}" ]]; then if [[ -n "${_ksi_prompt[ps1_suffix]}" ]]; then
PS1=${PS1//\\\[\\e\]133;k;start_suffix_kitty\\a\\\]*end_suffix_kitty\\a\\\]}
PS1="${PS1}${_ksi_prompt[ps1_suffix]}" PS1="${PS1}${_ksi_prompt[ps1_suffix]}"
fi fi
if [[ -n "${_ksi_prompt[ps2]}" ]]; then if [[ -n "${_ksi_prompt[ps2]}" ]]; then