atuinsh / atuin

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

Unable to import structured history data from hishtory into atuin and have the atuin program search it #2345

Open matthewcmead opened 1 month ago

matthewcmead commented 1 month ago

What did you expect to happen?

I've been using https://github.com/ddworken/hishtory/ for global history capture and would like to migrate to atuin. I have been unable to find a way to import hishtory's structured history data into atuin in a way that atuin will use. Here's what I've done:

I've used clickhouse-local with the following SQL to transform the hishtory data to atuin's schema:

create database hishtory Engine = SQLite('.hishtory/.hishtory.db');
select distinct id, start_time timestamp, end_time-start_time duration, exit, command, cwd, id session, hostname, null deleted_at from (select lower(hex(MD5(concat(local_username, '//', hostname, '//', command, '//', current_working_directory, '//', start_time, '//', end_time)))) id, toUnixTimestamp64Nano(parseDateTime64BestEffort(start_time)) start_time, toUnixTimestamp64Nano(parseDateTime64BestEffort(end_time)) end_time, exit_code exit, command, current_working_directory cwd, hostname from hishtory.history_entries);

I then exported this to TSV, and used sqlite3 to load the history data into atuin's history.db file:

.mode tabs
.import history hishtory.tsv

I'm then able to see the entries in the sqlite table.

What happened?

I expected atuin to allow me to search these prior history entries, but it does not. Is there some mechanism to get atuin to sync all its internal data off the history.db history table and incorporate it future executions of the program?

Thanks!

Atuin doctor output

% atuin doctor
Atuin Doctor
Checking for diagnostics

Please include the output below with any bug reports or issues

{
  "atuin": {
    "version": "18.3.0",
    "sync": null,
    "sqlite_version": "3.44.0"
  },
  "shell": {
    "name": "zsh",
    "default": "zsh",
    "plugins": [
      "atuin"
    ],
    "preexec": "built-in"
  },
  "system": {
    "os": "Darwin",
    "arch": "arm64",
    "version": "14.5",
    "disks": [
      {
        "name": "Macintosh HD",
        "filesystem": "apfs"
      },
      {
        "name": "Macintosh HD",
        "filesystem": "apfs"
      }
    ]
  }
}

Code of Conduct

ellie commented 1 month ago

Hey!

history.db isn't meant to be written to externally. We have a central source (records.db) that stores history encrypted, ready to sync. If it's not added to records, it won't function properly. We have an import function that handles history from other sources, and ensures it's stored correctly.

I'd suggest one of the following

  1. Convert the format to something we support importing. Resh or zsh-histdb might be a good option. https://github.com/atuinsh/atuin/tree/main/crates/atuin-client/src/import
  2. If you're comfortable doing so, writing an importer specifically for hishtory would be amazing! I imagine it wouldn't be too hard to base off of an existing importer