diff options
author | Koichi Murase <myoga.murase@gmail.com> | 2024-04-08 21:03:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 13:03:07 +0100 |
commit | 426ca5de3e074a7934b0190691d0b008fa729bdf (patch) | |
tree | b09eef6af1df020e015a7dc758ffe08e13de997f | |
parent | 28084a09636a4b8b8de5ad698c148b8fe6a1a9dd (diff) |
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
-rw-r--r-- | atuin/src/shell/atuin.bash | 24 |
1 files 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 |