From be1f6fd5ca718f725a840f764f387ccf4acf8a9f Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 29 Dec 2023 04:34:34 +0900 Subject: [PATCH] fix(bash): fix loss of the last output line with enter_accept (#1463) 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 bd9506e5..d04f1d9e 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