From f277cbf3f3fe03cecaec7e619bf8d8970d945dfa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Sep 2021 21:06:28 +0530 Subject: [PATCH] Improved trailing newline handling in the fish shell integration Thanks to some assistance from @faho See https://github.com/kovidgoyal/kitty/issues/4032#issuecomment-919936913 --- shell-integration/kitty.fish | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shell-integration/kitty.fish b/shell-integration/kitty.fish index 34738c7f8..e54ff4346 100644 --- a/shell-integration/kitty.fish +++ b/shell-integration/kitty.fish @@ -60,8 +60,13 @@ function _ksi_main function _ksi_end_prompt set --local cmd_status "$status" - set --local op (_ksi_original_fish_prompt | string collect) # trim trailing newlines to mimic fish behavior - printf "%s" "$op" + # fish trims one trailing newline from the output of fish_prompt, so + # we need to do the same. See https://github.com/kovidgoyal/kitty/issues/4032 + set --local op (_ksi_original_fish_prompt) # op is an array because fish splits on newlines in command substitution + if set -q op[2] + printf '%s\n' $op[1..-2] # print all but last element of array, each followed by a new line + end + printf '%s' $op[-1] # print the last component without a newline set --global _ksi_prompt_state "prompt_end" _ksi_mark "B" return "$cmd_status" # preserve the value of $status