atuinsh / atuin

✨ Magical shell history
https://atuin.sh
MIT License
20.63k stars 561 forks source link

Programmatic import #2431

Open pawamoy opened 3 days ago

pawamoy commented 3 days ago

So I have been using my own history tool for quite some time now, and have 220K+ commands in a file (+ other backed up files from other machines), in a custom format, that I'd like to import in Atuin :slightly_smiling_face:

How would I go about feeding Atuin programmatically, since surely the import subcommand will not support my history file format? You can assume I have all the necessary fields (and more :smile:).

pawamoy commented 3 days ago

Hmmm I guess I could simply check the database schema and insert things in it directly ^^

ellie commented 3 days ago

It's not quite that simple I'm afraid. We actually have two databases, and it's important to ensure that data is copied across them properly.

  1. records.db: this stores your shell history data encrypted, on disk. It's used for syncing cross-machine, and is not at all editable manually
  2. history.db: this contains your actual shell history data, in a format we can search and browse

I'd first disable auto-sync if you've already set it up. auto_sync = false in your config file.

There is a command that will take the data from history.db, and insert it into records.db. Once you've inserted to history.db, run:

atuin history init-store

This should be idempotent, and the process may happen automatically at sync time.

Once complete, I'd issue

atuin store rebuild history

This will wipe out history.db, and rebuild it from the records.db. Just to make sure everything is consistent!

Then, run

atuin sync

You should be good to go from here, and can re-enable auto_sync.

ellie commented 3 days ago

also - love all the graphs from your tool!

pawamoy commented 3 days ago

Awesome, thank you so much for the clear instructions! I'll try that and report back :slightly_smiling_face:

also - love all the graphs from your tool!

Thanks! I believe you have everything you need to offer similar graphs in Atuin too :smile: I could actually consider contributing if that's something you're interested in :relaxed: