Skip to content
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

atuin import zsh imports history in reverse order? #178

Open
leogama opened this issue Sep 1, 2021 · 3 comments · May be fixed by #2370
Open

atuin import zsh imports history in reverse order? #178

leogama opened this issue Sep 1, 2021 · 3 comments · May be fixed by #2370
Labels
bug Something isn't working help wanted Extra attention is needed shell-zsh

Comments

@leogama
Copy link

leogama commented Sep 1, 2021

I've just installed atuin in my Ubuntu 20.04, ZSH 5.8 pc using the deb package in Releases.

Running atuin import zsh (or auto) successfully imports my command history, but the imported commands then show up in reverse order when searching it through atuin. That makes no sense... Commands saved after the import and correctly appended to the history file appear in the right order.

Is it a timestamping issue? My history file had no timestamp or extra info, just the plain commands. I noted that atuin adds timestamps to ZSH history file.

For now, I've just reverted the history file with tac before importing and got it done. 👍🏼

@misuzu
Copy link

misuzu commented Apr 16, 2023

Same issue (v14.0.0, NixOS), same solution...

@LeoniePhiline
Copy link
Contributor

LeoniePhiline commented Aug 1, 2023

I can confirm, with atuin 15.0.0:

$HISTFILE (~/.zsh_history), oldest on top (as if ordered by timestamp ASC):
grafik

.local/share/atuin/history.db, with ORDER BY timestamp DESC, showing the oldest zsh entries on top as if they were the newest, since timestamps are assigned in reverse.
grafik

The timestamps are created as now - seconds(counter), counting upwards while iterating through the history file. This way, the top items are placed close to now, while the bottom items are placed "the longest ago".

https://github.com/atuinsh/atuin/blob/main/atuin-client/src/import/zsh.rs#L82-L88


Edit: This should also affect other importers. They use the same iterator and counter to manipulate timestamps.

My take is that the entire UnixByteLines must be made double ended and read in reverse by default.

As a workaround, all lines can be counted to know how far back the oldest (and first in the list) items to place on the timeline.

It might be pragmatic to just collect the iterator into a Vec and reverse that.

@ellie ellie added the help wanted Extra attention is needed label Jan 22, 2024
@ajesipow ajesipow linked a pull request Aug 24, 2024 that will close this issue
2 tasks
@ajesipow
Copy link

I opened a PR or this. Looking forward to feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed shell-zsh
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants