从终端中获取fzf的输出而不执行它

Get output from fzf in the terminal without executing it

fzf rocks! I want to use it to search bash history. When a match is found, I want it to be placed on the command line, but not executed so I can edit it further. (All of this is in a sourced bash function or script so it has access to my history.)

I have it almost working, but not quite.

This selects the command, but runs it immediately:

eval $(history | "$HOME/bin/fzf" +s | sed 's/ *[0-9]* *//')

This gets it into my clipboard, but when I paste it, it still ends with a blank and a newline so it executes immediately.

history | "$HOME/bin/fzf" +s | sed 's/ *[0-9]* *//' | xclip -se c

I also tried a couple of variations including

history | "$HOME/bin/fzf" +s | sed -e 's/ *[0-9]* *//' -e 's/$//' | xclip -se c

with the same result.

This actually works, but I still have to put it in the clipboard and then manually paste it.

history | "$HOME/bin/fzf" +s | sed -re 's/ *[0-9]* *//' | awk '{printf "%s", $0}' | xclip -se c

How can I do this in one step - without a manual paste?

I thought just leaving off the xclip would do it, but it doesn't work.

Seems to me that junegunn already solved this problem for you. In this file he replaces the bash ctrl-r with exactly the functionality you are after. I did have a small problem sourcing this file because of the line fzf-file-widget outputing sh: ``fzf-file-widget': not a valid identifier, but after changing that for fzf_file_widget it works great.