fix(shell): fix incorrect timing of child shells #1510
Merged
+4
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a child shell session is started from another shell session (let us call this parent session hereafter), the environment variable
ATUIN_HISTORY_ID
set by the parent session causes Atuin's precmd hook of the child session to be unexpectedly performed before the first call of Atuin's preexec hook.For example, let us consider the case to run
bash
inside the terminal to start a new session.In this patch, we clear
ATUIN_HISTORY_ID
(possibly set by the parent session) on the startup of the session. The variableATUIN_HISTORY_ID
doesn't seem to be an environment variable in the fish integration, but we clear it also in the fish integration for consistency.Possible drawback
With this solution, when the user runs
source .bashrc
(oreval "$(atuin init bash)"
) in the command line, theATUIN_HSITORY_ID
forsource .bashrc
is lost and the timing for that command is not recorded. However, the same happens for theexit
command. In the sense thatsource .bashrc
terminates the existingATUIN_SESSION
(and creates another), it is similar toexit
. For this reason, we might not need to care about it more thanexit
.Other possible solutions
However, another possible option would be not to make
ATUIN_HISTORY_ID
the environment variable from the beginning. As far as I search in the codebase, there does not seem to be a code that reads the environment variableATUIN_HISTORY_ID
from other processes. So I do not see the necessity to make the variable an environment variable.Or, with the current
main
, we are effectively measuring the startup time of the child shell. Maybe we can keep the current code if this is the intended one, but then, this seems inconsistent: In this way, only the startup times of the child sessions are measured, but the startup time of the parent session (the login shell started by the terminal) is not measured. Also, this does not work in the current integration with the fish shell because ATUIN_HISTORY_ID doesn't seem to be an environment variable in the fish integration.Review request
In this patch, I touch the integrations with all the shells, but I'm only familiar with Bash. If possible, I'd like reviews from the contributors to the integrations with the other shells: @ellie (for zsh, etc.), @conradludgate (for fish, etc.), @stevenxxiu (for nu), and @sophiajt (for env in nu)