From 426ca5de3e074a7934b0190691d0b008fa729bdf Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 8 Apr 2024 21:03:07 +0900 Subject: [PATCH] fix(bash): do not use "return" to cancel initialization (#1928) We have introduced initialization guards in #1533 [1], where `return 0` was used to cancel the initialization. However, this cancels the processing of the caller (which is typically `~/.bashrc`) instead of just canceling Atuin's initialization. In this patch, we avoid using `return 0`. Instead, we enclose the main part of the initialization in a big if-statement. [1] https://github.com/atuinsh/atuin/pull/1533 --- atuin/src/shell/atuin.bash | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index ba4f2cc2..1266b8d8 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -1,15 +1,16 @@ # Include guard -[[ ${__atuin_initialized-} == true ]] && return 0 -__atuin_initialized=true - -# Enable only in interactive shells -[[ $- == *i* ]] || return 0 - -# Require bash >= 3.1 -if ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 1)); then +if [[ ${__atuin_initialized-} == true ]]; then + false +elif [[ $- != *i* ]]; then + # Enable only in interactive shells + false +elif ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 1)); then + # Require bash >= 3.1 [[ -t 2 ]] && printf 'atuin: requires bash >= 3.1 for the integration.\n' >&2 - return 0 -fi + false +else # (include guard) beginning of main content +#------------------------------------------------------------------------------ +__atuin_initialized=true ATUIN_SESSION=$(atuin uuid) ATUIN_STTY=$(stty -g) @@ -318,3 +319,6 @@ if [[ $__atuin_bind_up_arrow == true ]]; then bind -m vi-command -x '"k": "\C-x\C-p"' fi fi + +#------------------------------------------------------------------------------ +fi # (include guard) end of main content