Skip to content

fix(bash): do not use "return" to cancel initialization#1928

Merged
ellie merged 1 commit into
atuinsh:mainfrom
akinomyoga:bash-include-guard
Apr 8, 2024
Merged

fix(bash): do not use "return" to cancel initialization#1928
ellie merged 1 commit into
atuinsh:mainfrom
akinomyoga:bash-include-guard

Conversation

@akinomyoga

@akinomyoga akinomyoga commented Apr 8, 2024

Copy link
Copy Markdown
Contributor

In #1533, I used return 0 for the "include guards" of Atuin's initialization. However, I noticed that it would unexpectedly cancel the entire processing of ~/.bashrc because it is evaluated by eval. This is my fault. In this PR, I suggest enclosing the entire content of the integration code within an if-statement.

Estimation on the impact

I expect the impact of return 0 would not be so big since the problem only happens when (i) ~/.bashrc is sourced twice in an interactive session, (ii) eval "$(atuin init bash)" is performed outside the interactive sessions, or (iii) it is performed in a very old version of Bash for which Atuin's integration doesn't offer the support. For case (ii), with a typical .bashrc starting with case $- in *i*) ;; *) return ;; esac (or equivalent), eval "$(atuin init bash)" is usually performed only in interactive sessions. For case (iii), Atuin's initialization anyway produces an error message, so the setup is technically wrong. If the user uses mixed versions of Bash, the user is supposed to check the Bash version at the caller side in ~/.bashrc before evaluating eval "$(atuin init bash)".

Checks

  • I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle
  • I have checked that there are no existing pull requests for the same thing

We have introduced initialization guards in atuinsh#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] atuinsh#1533

@ellie ellie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I see, nice fix. thanks!

@ellie ellie merged commit 426ca5d into atuinsh:main Apr 8, 2024
@akinomyoga akinomyoga deleted the bash-include-guard branch April 8, 2024 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants