Changing the host associated with commands in history

I like to use the “host” filter mode by default, but I recently changed the hostname of my computer breaking command history. Is there a way to rename a host in the history to match the new one, or something similar that would let me “move over” my command history to the new hostname? I use sync if that’s relevant, and there are multiple other hosts on there.

1 Like

I’m in the exact same situation. This feature is badly needed!

1 Like

Same here. Probably could be done with sqlite hacking too but a CLI based approach would of course be vastly preferable.

+1, same requirements

This is definitely something we should do, though we need to add a new sync primitive first. Currently we only sync operations for creating or deleting history records, we’d need an additional one for editing

Relevant enum

1 Like

I ran this to update my old hostname (on one primary machine):

#!/bin/bash
ATUIN_DIR="$HOME/.local/share/atuin"
HISTORY_DB="$ATUIN_DIR/history.db"
TEMP_DB="/tmp/atuin_transform.db"

# 1. Create a working copy for transformations
# We use .backup to ensure we start with a clean, non-WAL state
sqlite3 "$HISTORY_DB" ".backup '$TEMP_DB'"

# 2. Run your hostname updates on the TEMP database
echo "[+] Updating hostnames in temporary buffer..."
sqlite3 "$TEMP_DB" <<EOF
UPDATE history SET hostname = 'new_hostname:new_user' WHERE hostname = 'old_hostname:old_user';
UPDATE history SET hostname = 'new_hostname:new_user' WHERE hostname IN ('old_hostname3:old_user3', 'old_hostname2:old_user2');
VACUUM;
EOF

# 3. Restore the transformed data into the LIVE database
echo "[+] Restoring transformed history to Atuin..."
sqlite3 "$HISTORY_DB" ".restore '$TEMP_DB'"

# 4. Cleanup and Re-index
rm -f "$ATUIN_DIR/records.db"* "$TEMP_DB"
atuin history init-store

echo "[!] Local database updated via .restore. Ready for 'atuin store push --force'."

then I run on the primary machine: atuin store push --force

finally, on each remote machine:

rm -f ~/.local/share/atuin/records.db"*
atuin store pull --force
atuin store rebuild history