Skip to content

fix(bash): avoid unexpected atuin history start for keybindings#1509

Merged
ellie merged 1 commit intoatuinsh:mainfrom
akinomyoga:fix1003-2
Jan 6, 2024
Merged

fix(bash): avoid unexpected atuin history start for keybindings#1509
ellie merged 1 commit intoatuinsh:mainfrom
akinomyoga:fix1003-2

Conversation

@akinomyoga
Copy link
Contributor

This fixes the second issue reported at #1003 by @gvlassis, i.e., the issue of "0s or wrong command duration".

The problem is that, with bash-preexec, the preexec hook may be called even for the commands executed by the keybindings.

  • In particular, the preexec is called before the command __atuin_history is executed on pressing C-r and up. In this case, $1 passed to __atuin_preexec contains the last entry in the command history, so atuin history start is called for the last command. As a result, pressing C-r and up clears the duration of the last command. This causes the reported 0s duration.

  • Furthermore, the precmd hook corresponding to the keybinding command will not be called, so the duration is only filled when the next user command starts. This replaces the duration of the last command with the time interval between the last press of C-r or up and the start time of the next command. This causes the reported wrong duration.

There is no general and robust way to distinguish the preexec invocation for keybindings from that for the user commands, but in this patch, we exclude the preexec invocation for Atuin's keybindings to C-r and up at least.

This fixes the second issue of "0s or wrong command duration" reported
at atuinsh#1003.

The problem is that, with bash-preexec, the preexec hook may be called
even for the commands executed by the keybindings.

* In particular, the preexec is called before the command
  `__atuin_history` is executed on pressing [C-r] and [up].  In this
  case, $1 passed to `__atuin_preexec` contains the last entry in the
  command history, so `atuin history start` is called for the last
  command.  As a result, pressing [C-r] and [up] clears the duration
  of the last command.  This causes the reported 0s duration.

* Furthermore, the precmd hook corresponding to the keybinding command
  will not be called, so the duration is only filled when the next
  user command starts.  This replaces the duration of the last command
  with the time interval between the last press of [C-r] or [up] and
  the start time of the next command.  This causes the reported wrong
  duration.

There is no general and robust way to distinguish the preexec
invocation for keybindings from that for the user commands, but in
this patch we exclude the preexec invocation for Atuin's keybindings
[C-r] and [up] at least.
@vercel
Copy link

vercel bot commented Jan 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
atuin-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 6, 2024 0:33am

Copy link
Member

@ellie ellie left a comment

Choose a reason for hiding this comment

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

lgtm, thank you

@ellie ellie enabled auto-merge (squash) January 6, 2024 16:43
@ellie ellie merged commit 86f2c8e into atuinsh:main Jan 6, 2024
@akinomyoga akinomyoga deleted the fix1003-2 branch January 6, 2024 20:06
@akinomyoga
Copy link
Contributor Author

Thanks!

@ellie
Copy link
Member

ellie commented Feb 17, 2024

Hey! It looks like this one caused a regression. I'm struggling to get bash to record much input at all with preexec and this patch. Reverting it solved all issues for me

akinomyoga added a commit to akinomyoga/atuin that referenced this pull request Feb 17, 2024
In GitHub atuinsh#1509, we blocked the unintended preexec caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

atuinsh#1509
atuinsh#1727
atuinsh#1728
akinomyoga added a commit to akinomyoga/atuin that referenced this pull request Feb 17, 2024
In GitHub atuinsh#1509, we blocked the unintended preexec caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

atuinsh#1509
atuinsh#1727
atuinsh#1728
akinomyoga added a commit to akinomyoga/atuin that referenced this pull request Feb 17, 2024
In GitHub atuinsh#1509, we blocked the unintended preexec caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

atuinsh#1509
https://forum.atuin.sh/t/atuin-bash-and-ble-sh/175
atuinsh#1003 (comment)
atuinsh#1727
atuinsh#1728
akinomyoga added a commit to akinomyoga/atuin that referenced this pull request Feb 17, 2024
In GitHub atuinsh#1509, we blocked the unintended preexec caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

atuinsh#1509
https://forum.atuin.sh/t/atuin-bash-and-ble-sh/175
atuinsh#1003 (comment)
atuinsh#1727
atuinsh#1728
akinomyoga added a commit to akinomyoga/atuin that referenced this pull request Feb 17, 2024
In GitHub atuinsh#1509, we blocked the unintended preexec event caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

atuinsh#1509
https://forum.atuin.sh/t/atuin-bash-and-ble-sh/175
atuinsh#1003 (comment)
atuinsh#1727
atuinsh#1728
ellie pushed a commit that referenced this pull request Feb 17, 2024
In GitHub #1509, we blocked the unintended preexec event caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

#1509
https://forum.atuin.sh/t/atuin-bash-and-ble-sh/175
#1003 (comment)
#1727
#1728
ellie pushed a commit that referenced this pull request Feb 26, 2024
In GitHub #1509, we blocked the unintended preexec event caused by the
keybinding of Atuin.  However, with that fix, the preexec event for
the intended user command is still missing.  In this patch, we try to
manually run the preexec hook when we detected the unintended preexec
(which means the missing intended preexec).

References:

#1509
https://forum.atuin.sh/t/atuin-bash-and-ble-sh/175
#1003 (comment)
#1727
#1728
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