- Where I learned about
fc -p(read in and replace) andfc -A(Append)
WARNING: using
fc -pwill replace your current history file with a blank one. Tread carefully.
GOAL: merge (or concat or join or append) a set of old zsh_history files into a single one.
Imagine you have 3 zsh history files, with timestamps from oldest to newest: zsh_history0, zsh_history1, zsh_history2.
The approach here is to
- Append
zsh_history1tozsh_history0 - Append
zsh_history2tozsh_history0(which will now also containzsh_history1data) - Replace
~/.zsh_historywith combinedzsh_history0
I'll note that I don't actually know what I'm doing. The following two approaches appeared to work?
OPTION 1
# first, make a copy of zsh_history0
cp zsh_history0 zsh_history_merged
# load in zsh_history1 then append it to zsh_history_merged
fc -p zsh_history1
fc -A zsh_history_merged
# load in zsh_history2 then append it to zsh_history_merged
fc -p zsh_history2
fc -A zsh_history_merged
# replace existing history file ($HISTFILE)
cp zsh_history_merged $HISTFILEOPTION 2
# load in zsh_history0
fc -p zsh_history0
# read in additional files
fc -I -R zsh_history1
fc -I -R zsh_history2
# write the files to zsh_history_merged
fc -W zsh_history_merged
# replace existing history file ($HISTFILE)
cp zsh_history_merged $HISTFILE