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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.