分享 在 pry console 中使用 fzf 搜索历史命令

fangxing204 · October 28, 2017 · Last by ceclinux-github replied at October 30, 2017 · 1764 hits

用了 fzf 之后感觉太好用了,但是工作经常使用 pry console, 网上也没有找到怎么将 fzf 用到 pry console 中,于是自己查资料,知道原来命令行有 Readline, zle(zsh line editor) 这种东西,然后找到了纯 ruby 的 Readline 实现,然后我覆写RbReadline中的rl_reverse_search_history 方法,在我的 pryrc 中添加了如下代码:

# ~/.pryrc
require 'rb-readline'

def RbReadline.rl_reverse_search_history(sign, key)
 rl_insert_text  `cat ~/.pry_history | fzf --tac |  tr '\n' ' '`
end

启动 pry, 按下 Ctrl +R , Cool !

参考: https://sgeb.io/posts/2014/04/zsh-zle-custom-widgets/
http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
http://bogojoker.com/readline/
https://ruby-doc.org/stdlib-2.1.1/libdoc/readline/rdoc/Readline.html

Cool!fzf 确实好用

非常酷,感谢分享

You need to Sign in before reply, if you don't have an account, please Sign up first.