How to load fish command history from file

Viewed 797

Is there a way to load commands-history of fish from a file?

I like to clear my history periodically, but keep a set of useful commands always in history for easily accessing.

In bash this can be done via:

history -r file.txt

Can this be done in fish?

1 Answers

In my experience what you want to do isn't really necessary since a) fish only remembers the most recent instance of a command and b) generally does a really good job of using available context to provide the most appropriate entry from the command history, and c) already trims old entries once the number of saved commands reaches a limit.

But, assuming you've saved your preferred history subset to ~/.local/share/fish/fish_history.save:

builtin history clear
cp ~/.local/share/fish/fish_history.save ~/.local/share/fish/fish_history
history merge

The builtin in the first instance is to avoid the prompt asking if you really want to clear your history. Note that your saved history has to be valid YAML. It's a text file but is a little more complex than just each command on a separate line.

Related