Every Linux user knows that the most frequently used key combination is Ctrl + R. You use it to search through your Bash history for some fragment of text you’ve previously inputted into the terminal, hitting the combo again and again until you find the command you need.
Stop your keycaps from wearing out by using McFly—a neural network-powered shell history search replacement, that takes your working directory and the context of recently executed commands into account.
Why Should You Use McFly to Search Your Shell History?
If you’ve been using Linux for any amount of time, you probably spend a good portion of your day on the command line. Whether you’re listening to internet radio, creating mind maps for your next project, or setting up a self-hosted workout and fitness manager, the Linux terminal is where you make the magic happen.
Many times you’ll repeat the same command over and over again, or at least, with slight modifications.
The easiest way to repeat a command is to use reverse-i-search by hitting Ctrl + R, then typing a part of the command. For instance, if you press Ctrl + R, then input:
…the reverse-i-search prompt will fill out the most recent command which contained the “ls” string or sub-string. Hit Ctrl + R again, and reverse-i-search will prompt you to use the next most recent, and so on.
You can hit Enter to execute the command, or the left or right arrow keys to edit it before executing.
It’s a great tool, but you can only see one entry at a time, and if you hit the combo one too many times by accident, you have to start again from the beginning.
McFly uses the same key combo as reverse-i-search and has the same basic functionality, but improves on it—allowing you to select from a list of the most likely candidates for the command you want to use, as well as a more intelligent way of making suggestions.
Install McFly as a reverse-i-search Replacement on Linux
Installing McFly is as simple as downloading and running a script created by the McFly developer. Open a terminal, and enter:
sudo sh install.sh
The first command downloads a script to download and install a binary release of a Rust crate hosted on GitHub, and the second command uses this script to download and install McFly.
McFly is now installed, but you can’t use it as a reverse-i-search replacement just yet. Use nano to edit your .bashrc file:
…and at the end of the file, add:
eval "$(mcfly init bash)"
Save and exit nano with Ctrl + O then Ctrl + X.
Close your terminal, then reopen it. Next time you use Ctrl + R, McFly will run in place of reverse-i-search.
Use McFly to Search Your Bash History!
Hit Ctrl + R, and you’ll instantly be in the McFly TUI (terminal user interface) with a blank prompt and a list of 10 most likely commands—so make sure your mum isn’t standing behind you if you frequently use yt-dlp to download anything naughty.
If your desired command is in the list, use the Up and Down arrow keys on your keyboard until your desired entry is highlighted. Press Enter to execute.
If you want to edit the command before launching, highlight the entry, then press the Tab key. You will be returned to the command prompt with the text already entered. Edit the command to suit your needs, then press Enter.
McFly employs a simple neural network to try and figure out what command you’re looking for. This takes into account variables such as what directory you’re currently in, how often you run the command, whether the command usually executes successfully, whether you’ve selected the command in McFly before, and when you last used the command.
While this usually works well and makes it easy to find the command you want to use, you may want to turn this feature off. Pressing F1 from within the McFly TUI will toggle the sorting mechanism to one based on time.
If there’s an embarrassing, compromising, or less-than-useful command you want to delete from your history entirely, highlight it and press F2.
Use Your Linux Terminal More Effectively
Now you can efficiently search and execute commands from your Bash history; it’s worthwhile replacing some old favorites from the 1970s with their modern alternatives.
Use bat instead of cat, duf instead of df, and btop instead of top or htop!