Problem In many cases, it is more convenient to leave the result in history than the command when using Interactive filter.
#Example: Open the file selected with fzf with vim
alias v='_vim_fzf'
_vim_fzf () {
local file
file=$(fzf +m -q "$1") && vim "$file"
}
In the above case, the selected file does not appear even if you go back in history.
Solution
Bash uses history -s
.
_vim_fzf () {
local file
file=$(fzf +m -q "$1") && history -s "vim $file" && vim "$file"
}
If you rewrite it like this, the vim [selected file]
will be recorded in the history instead of the v
command, so you can reopen the file with Ctrl-R or Ctrl-P.
Further Work (Zsh)
In Zsh, print -s
seems to be equivalent.
$ print -s "alternative command"
$ history
# ...
# 99 print -s "alternative command"
# 100 alternative command
The problem is that the print
command itself is also saved as above. Please let me know if there is a better way mm
Recommended Posts