Smarter bash history

When using bash the up/down arrows are useful to browse through the recent commands.

But since the wanted command may be a bit up in the history stack it can be a bit tedious to find the right command.

For example, I know that I had a long nice cat + grep + awk line earlier it might require many up-arrow presses or a history | grep cat…

Instead I added small script file to /etc/profile.d/complete_history.sh

if [ ! -z "$PS1" ]; then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi

You probably need to make it executable…

Now after starting a new bash instance I can write:

cat [up-arrow]

This will only give me the history entries starting with cat …

If you started the line with the wrong keyword use CTRL+C to break out…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s