24

Merge two zsh history files

 2 years ago
source link: https://gist.github.com/calexandre/63547c8dd0e08bf693d298c503e20aab
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Instantly share code, notes, and snippets.

Merge two zsh history files

thanks!

zsh can do this itself:

    builtin fc -R -I "$hist_file"
    builtin fc -R -I "$another_hist_file"

    # write the loaded history to HISTFILE
    builtin fc -W "$HISTFILE"

This was exactly what I needed. Thanks for sharing!

Sweet! Thanks to both of you for providing options. I went with the builtin solution and it worked great.

borekb commented 13 days ago

@NightMachinery This is great and works when I paste it to a terminal manually, however, it doesn't work for me when I create a script like merge-zhs-histories.sh. I tried this:

#!/usr/bin/env zsh

hist_file_1="/Users/borekb/.zsh_history"
hist_file_2="/Users/borekb/.zsh_history (1)"
hist_file_merged="/Users/borekb/.zsh_history-MERGED"

builtin fc -R -I "$hist_file_1"
builtin fc -R -I "$hist_file_2"

builtin fc -W "$hist_file_merged"

The .zsh_history-MERGED file is not created for me (but it is created when I copy/paste the code to my terminal).

Is that something specific about builtin fc? Or am I making some obvious mistake?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK