Skip to content

Instantly share code, notes, and snippets.

@kforeverisback
Last active April 8, 2024 10:10
Show Gist options
  • Save kforeverisback/ad1f5d233e9c1147d26fa23db22b0498 to your computer and use it in GitHub Desktop.
Save kforeverisback/ad1f5d233e9c1147d26fa23db22b0498 to your computer and use it in GitHub Desktop.
Import McFly history into Atuin

Recently I started to move from McFly to Atuin and wanted to quickly import McFly history.

But atuin didn't include a method to import Mcfly history. So here is my short procedure:

McFly --> Zsh history format --> Zsh History (merge) --> Atuin import:

For ZSH

# Make sure McFly is still your history manager
# Dump `mcfly` history
mcfly dump > ./mcfly-hist.json

# Now convert the json file with JQ and convert
# Pretty sure there is a faster way to do this, but I am lazy :), it works, takes few seconds for my 10k hist
jq -r 'sort_by(.when_run) | .[] | [.when_run, .cmd]|@tsv' ./mcfly-hist.json | while IFS=$'\t' read -r when_run cmd; do printf ": %s:0;%s\n"  "$(date -d $when_run +%s)" "$cmd"; done >| /tmp/hist_mcfly

# Stop current Z-shell's history
fc -p # Turns on memory hist

# Concat Exported history to ZSH history
# Make a backup PLEASE!
cp ~/.zsh_history{,_bak}

# Replace the current history
cat /tmp/hist_mcfly ~/.zsh_history_bak | sort | uniq >| ~/.zsh_history

# Assuming your shell didn't crap out, import into Atuin
atuin import zsh

# Exit Or CTRL+D to exit current shell which has in-mem hist
exit

For Bash

# Make sure McFly is still your history manager
# Dump `mcfly` history
mcfly dump > ./mcfly-hist.json

# Now convert the json file with JQ and convert
# Pretty sure there is a faster way to do this, but I am lazy :), it works, takes few seconds for my 10k hist
jq -r 'sort_by(.when_run) | .[] | [.cmd]|@tsv' >| /tmp/hist_mcfly

# Stop current Bash history
set +o history # Disables history

# Concat Exported history to ZSH history
# Make a backup PLEASE!
cp ~/.bash_history{,_bak}

# Replace the current history
cat /tmp/hist_mcfly ~/.bash_history_bak | sort | uniq >| ~/.bash_history

# Assuming your shell didn't crap out, import into Atuin
atuin import bash

set -o history  # enables history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment