From ccf0c92e36c7b0b3e4a5469bf21465a9e1cbd1b6 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Thu, 28 Dec 2023 21:31:43 +0900 Subject: [PATCH] fix(bash): fix loss of the last output line with enter_accept With a single-line prompt, the last line of the output of the previous command is overwritten by the prompt on the enter_accept. In this situation, `tput cuu` receives 0 as the argument, but `tput cuu 0` emits the control sequence `\e[0A`, which moves the cursor above by one line unexpectedly. This is because the parameter 0 for CUU means the default value, 1. In this patch, to avoid moving the cursor when the prompt offset is 0, we check the offset value before running `tput cuu`. --- atuin/src/shell/atuin.bash | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index bd9506e5c08..d04f1d9e457 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -29,8 +29,11 @@ __atuin_history() { then HISTORY=${HISTORY#__atuin_accept__:} # Reprint the prompt, accounting for multiple lines - # shellcheck disable=SC2046 - tput cuu $(echo -n "${PS1@P}" | tr -cd '\n' | wc -c) + local __atuin_prompt_offset + __atuin_prompt_offset=$(echo -n "${PS1@P}" | tr -cd '\n' | wc -c) + if ((__atuin_prompt_offset > 0)); then + tput cuu "$__atuin_prompt_offset" + fi echo "${PS1@P}$HISTORY" if [[ -n "${BLE_VERSION-}" ]]; then