-
-
Notifications
You must be signed in to change notification settings - Fork 721
fix(bash): work around bash < 4 and introduce initialization guards #1533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Although this can be broken by various conditions, if would like to introduce, this one I can consider the possibility of implementing it.
How broken would it be, and by what conditions?
|
ah, some conflicts that need resolving before we can merge |
In bash < 4, the variables READLINE_LINE and READLINE_POINT are not supported for the shell commands called by `bind -x`. Even if it is not supported, atuin works in not a bad way. However, this sometimes causes a strange behavior by the remaining values of READLINE_LINE set in the previous calls of __atuin_history. In bash < 4, we can consistently use an empty string instead of $READLINE_LINE, and the changes to READLINE_LINE and READLINE_POINT should be localized within the function.
In bash, it is customary to reload the settings by sourcing `.bashrc` again after modifying it. In such a case, `eval "$(atuin init bash)"` is executed again. This registers duplicate hooks to `preexec_functions` and `precmd_functions`. To prevent this in this patch, we introduce an include guard, so that the initialization is not performed more than once.
98f01c4 to
aa29a94
Compare
|
Thank you for reviewing. For the conflict, I've rebased those commits on top of the current
What is done in |
Hm I see. Best to be avoided then imo - thank you! |
|
Thanks! |
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
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] #1533
(First commit) Check interactive shell.
In a typical configuration of
.bashrc, in an interactive session (where$-contains the letteri), it returns at the beginning of~/.bashrc. However, a different configuration is possible. In such a case,eval "$(atuin init bash)"can be called from non-interactive shells, and causes error messages related to the keybindings, i.e., the uses of thebindcommand in non-interactive shells causes warning messages. We can have a check also at the beginning ofatuin.bash.(Second commit) Check the Bash version
The requirement on the Bash version does not seem to be clarified anywhere, so I suggest explicitly specifying it to be bash >= 3.1. This is the same as that of bash-preexec.
enter_accept. In Bash 3.1 & 3.2, there is no way to obtain the content of the current command line becauseREADLINE_LINEandREADLINE_POINTare only introduced in bash >= 4. This forces Atuin to always start with the full history for the search (without filtering by the current command-line content), but it still works withenter_accept. Also, there is no way to clear up the current command-line content afterenter_accept. This behavior might feel a bit strange, but it's still acceptable.enter_accept, there is no robust way to insert the suggestion in the command line. I here suggest just noting that in README. Alternatively, we could still insert the suggestion by doing a hack similar to what is done byfzf-keybindings.bashL110. Although this can be broken by various conditions, if would like to introduce, this one I can consider the possibility of implementing it.READLINE_LINEandREADLINE_POINTalso for Bash 3.(Third commit) Work around missing READLINE_LINE in Bash 3 w/ bash-preexec
However, in bash < 4, there is still possibly a strange behavior caused by the remaining
READLINE_LINEfrom the previous call ofatuin. To prevent it, I suggest localizingREADLINE_LINEandREADLINE_POINTin bash < 4 without ble.sh. I also left some descriptions in the commit message.(Fourth commit) Avoid double initialization
See the commit message. As another option, we may add our hooks into
preexec_functionsandprecmd_functionsonly when there are no existing ones. This enables the reloading of Atuin's settings in the same shell session after updating Atuin. If you'd like it this way, I can adjust the PR.