In my fish function, I'm evaluating constructed commandline via
eval (commandline)
, specifically - I'm looking for some file name from fzf, and then analyze if commandline was prepended with vim
. If it was - instead of returning vim filename
to press enter afterwards, I just evaluate it, as I showed before.
The thing is that if I evaluate it, instead of pressing enter manually, it is not going to history - e.g. I can not see it as previous command by pressing up.
I tried set -x history (commandline) $history
after eval, but it shows me an error set: Tried to change the read-only variable “history”
Is there a way to manually add custom string (in my case commandline buffer) to history? thx.
history --merge
does not merge history in chronological order #2312. So even if we manually add the command to~/.config/fish/fish_history
we will no be able to simply press up to see it (although you will get to it eventually if you press up enough).To get around this we can make a copy of
fish_history
then callbuiltin history --clear
which will clear both fish's internal history and the history file. We then restore the history file from our copy, append our command and callhistory --merge
to merge the history file with the now empty internal history.