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

Add history export (and re-import) option, machine-readable #816

Open
shoffmeister opened this issue Mar 26, 2023 · 3 comments
Open

Add history export (and re-import) option, machine-readable #816

shoffmeister opened this issue Mar 26, 2023 · 3 comments

Comments

@shoffmeister
Copy link

It could be a useful addition to atuin to offer history export, reimport/merge in a machine-readable, open, stable format.

I did find the SQLite database in ~/.local/share/atuin, but that's "locked away" in a sense, IMHO, requiring SQLite tooling.

Using JSON as data exchange format, it would be possible to

  • backup transparently the history - e.g. atuin history list --json, sitting next to the --format option
  • replace existing history, e.g. atuin history replace --json < my-history.json
  • merge / append existing history, e.g. atuin history append --json < my-history.json
  • run filtering, e.g. atuin history list --json | jq ' <fancy-filtering-here> ' | atuin history append --json

This would be particularly useful in scenarios where there is no Atuin server around, only sneakernet.

Disclaimer: I only just installed atuin, with one major attraction being the global shell history across bash sessions (something that fzf does not / cannot offer).

@conradludgate
Copy link
Collaborator

  • backup transparently the history - e.g. atuin history list --json, sitting next to the --format option
  • merge / append existing history, e.g. atuin history append --json < my-history.json

You might know we already have a sync service. This uses JSON already, but the payloads are encrypted.

In theory we could have a cli version too. But it needs a proper design. We have some ideas on the roadmap. I'll see if we can fit this in with our new ideas too.

Thanks for the suggestion

@tennox
Copy link

tennox commented Nov 18, 2024

"Workaround" script (nushell, but you get the point):

atuin search -c $session_dir --format '"command": "{command}", "directory": "{directory}", "duration": "{duration}", "user": "{user}", "host": "{host}", "time": "{time}", "exit": "{exit}", "relativetime": "{relativetime}"' 
        | str trim | each {|s| '{' + $s + '}'} # = surround with curly braces
        | save "export.jsonl" # save to jsonl file

(note: can't put { in format string, not even \{ 😅 )

@tombh
Copy link
Contributor

tombh commented Jan 18, 2025

Here's a little script I'm using to keep my Atuin history synced with my Nushell history. I run it to both import and to sync when I delete items from history.

The only reason I sync Atuin and Nushell is just because I like those ZSH-style autocompletions as you type, which as far as I know Atuin only currently natively supports for ZSH itself.

# Remember to change the DB paths to your own.
echo "\
  ATTACH DATABASE '/home/tombh/.local/share/atuin/history.db' AS atuin;\
  DELETE FROM history;\
  INSERT INTO history(command_line, start_timestamp, hostname, cwd, duration_ms, exit_status) \
               SELECT command,      timestamp,       hostname, cwd, duration,    exit         FROM atuin.history;\
" | sqlite3 ~/.config/nushell/history.sqlite3

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

No branches or pull requests

4 participants