Skills of efficiently matching history commands in bash

Complete the history command in bash

This article introduces the best bash configuration skills I think. Once you configure, you will benefit every day.

In bash, the most common way to search history commands is ctrl + r , but this step is too many and troublesome.

Here is a very fast completion method.

Execution:

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

In this way, first enter some commands, and then press the Up/Down You can automatically complete the history command.

working principle

Actually ~/.inputrc The following content has been added to the file:

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

The first two lines are bound to shortcut keys. What do the last two lines mean?

show-all-if-ambiguous It means that when a tab is completed, pressing the tab once will automatically complete the longest match. Specific reference https://stackoverflow.com/a/42193784

completion-ignore-case It is also very convenient to ignore case when completing a tab.

Note that after modification ~/.inputrc Files, to execute explicitly bind -f ~/.inputrc Will take effect.

As an aside, in arthas Li also supported Up/Down This feature automatically completes the history command, so in the arthas The automatic completion of history command in is very convenient.

 Hengyunabc wechat
Welcome to scan the above WeChat official account and subscribe to the column of Hengyun Broken Ridge