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
This commit is contained in:
Koichi Murase 2024-04-08 21:03:07 +09:00 committed by GitHub
parent 28084a0963
commit 426ca5de3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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