RSS Amplifier

Bash Prompt · Jan 9, 2021

Intelligent Console History Search

0
Sign in to vote or save

Elliot Cooper · Bash Prompt

Everyone knows, or should know, that typing CTRL+R on the command line and typing something will perform a reverse search through your command history.

This system can be improved upon.

With the code shown below you can start typing on the command line then hit the up-arrow to match the last instance in yoru history of what you have’ve written. Pressing the up-arrow again will print the match after the first and so on.

The code to do this is as follows:

export HISTFILESIZE=
export HISTSIZE=
export HISTCONTROL=erasedups
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'

Simply copy and paste this into your ~/.bashrc file and then reload local environment:

source ~/.bashrc

You’re all set to give it a test.

Read the original on bash-prompt.net

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.