FOSSPicks
History search
McFly
One of the best features of the Bash command line is its history, handily stored in the .bash_history
file, so it can be easily deleted. Apart from searching through the file manually, or with the history
command, and using the up and down cursor keys to manually step through the history, its best trick is accomplished by pressing Ctrl+R to initiate a search. This lets you search for commands you know you typed but don't know exactly where to find. As soon as you've mastered Ctrl+R, it becomes a part of almost every command incantation on the command line. But Ctrl+R for history is also somewhat limited in its search capabilities, and that's where McFly comes in.
McFly is a Ctrl+R history replacement for the command line. It's easily installed via Rust's Cargo package manager and requires a single line added to your shell config. The first time you run your Bash terminal after installing McFly, it creates a database from your history, and this takes a few seconds. The new database includes added details, such as exit status and time stamp, but your old history is also maintained in parallel. The indexing is only done on the first launch, so it isn't too much of an inconvenience. You're then left with your normal prompt and the tantalizing possibilities that lie behind pressing Ctrl+R. Start typing a command, and pressing Ctrl+R takes you into a full-screen terminal application, complete with fuzzy search results listed below your prompt. This is the clever part, because behind the scenes a neural network is sorting these results, taking into account your current directory, the commands before the current one, when you last ran the command, and other variables. You can navigate through the results, but they're often so good you won't need to. It works like magic and can transform the way you use the command line.
Project Website
https://github.com/cantino/mcfly
Regex parser
Buy this article as PDF
(incl. VAT)