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

fangxing204 · 2017年10月28日 · 最后由 ceclinux-github 回复于 2017年10月30日 · 1770 次阅读

用了 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 确实好用

非常酷,感谢分享

需要 登录 后方可回复, 如果你还没有账号请 注册新账号