64

一次配置,每天受益的Bash命令补全技巧

 4 years ago
source link: https://www.tuicool.com/articles/2mu26rF
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在bash里补全历史命令

本文介绍本人觉得最好用的bash配置技巧,一次配置,每天受益。

在bash里,最常见的搜索历史命令的办法是 ctrl + r ,但是这个步骤太多,比较麻烦。

下面介绍一种非常快捷的补全方式。

执行:

curl -L http://hengyunabc.github.io/bash_completion_install.sh | sh
bind -f  ~/.inputrc

这样子,先输入部分命令,再按键盘的 Up/Down 就可以自动补全出历史命令了。

工作原理

实际上给 ~/.inputrc 文件添加了下面的内容:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

前面两行自然是绑定了快捷键,后面两行是什么意思呢?

show-all-if-ambiguous 是指tab补全时,按一次tab就会把最长匹配的自动补全。具体参考 https://stackoverflow.com/a/42193784

completion-ignore-case 是指tab补全时,忽略大小写,这点也非常方便。

注意,在修改完 ~/.inputrc 文件,要显式执行 bind -f ~/.inputrc 才会生效。

题外话,在 arthas 里也支持了 Up/Down 自动补全历史命令这个特性,所以在 arthas 里自动补全历史命令非常的方便。

  • https://github.com/alibaba/arthas


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK