DEV Community

Better bash history search with McFly

Juha-Matti Santala on January 28, 2019

If there's one functionality of bash that most beginners don't know but get very excited about when they discover it, it's history. First you learn...
Collapse
 
detunized profile image
Dmitry Yakimenko

I've been using fzf with some keybindings. The added benefit is that fzf is a general purpose fuzzy autocomplete engine, it possible to pick a directory or a file in a similar fashion. It's pretty snappy too.

Collapse
 
hamatti profile image
Juha-Matti Santala

Thanks for sharing Dmitry! I'll have to check it out and give it a go.

Collapse
 
n8kowald profile image
Nathan

McFly looks great.
Makes it easy to visually find the command you're after by showing a list.
Thanks for sharing!

I've been using this in my ~/.bash_profile for an easier CTRL+R experience using the up arrow.

bind '"\e[A"':history-search-backward
bind '"\e[B"':history-search-forward

It completes from your bash history using the up keyboard key.

# Using the up keyboard key you can cycle through your last used commands starting with "cows"
cows[UP]

If you've cycled through a few commands pressing the down arrow brings the previously cycled commands back.

Collapse
 
hamatti profile image
Juha-Matti Santala

That's such a smart improvement, thanks for sharing!