Replacing history with McFly
Command Line – McFly

© Photo by Shiro hatori on Unsplash
McFly improves on the venerable history command with a customizable interface and contextualized results.
The history
command brings previously used commands forward to use again. So what could be a more appropriate name for a history
replacement than the last name of Michael J. Fox's character in Back to the Future? McFly [1] replaces history
with an improved interface and more contextualized results that are generated with an AI-based algorithm and an SQLite database. Although no quicker with results than history
, McFly offers numerous advantages:
- Results are displayed full-screen, with basic commands summarized in the titlebar (Figure 1).

- Information is given about when a result was run and in which directory, if it was not in your home directory, as well as if it failed. Failed results are usually not displayed.
- Priority is given to the present working directory.
- Results take into account other commands that in the past were run after the command.
Unlike the history
command (Figure 2), McFly does not number results, so you can cannot jump to a specific one. However, numbering is rarely useful, and McFly's contextualized results, as well as the ability to launch a command from the results page, more than compensate for the lack of numbering. Similarly, the ability to edit a result in McFly means that history
's complicated editing tools are unnecessary. In addition, McFly's structure is easier to use than history
's, which many users ignore when searching history
in favor of the up and down arrow keys.

Installing and Configuring McFly
McFly runs on the Bash and Zsh command shells, with support for the fish shell in development. McFly can be installed using Homebrew [2] or using its installation script. To use the installation script as shown in Figure 3, run the following with root privileges:
curl -LSfs https://raw.githubusercontent.com/cantino/mcfly/master/ci/install.sh | sh -s -- --git cantino/mcfly

Then add the following line to the ~/.bashrc
file
eval "$(mcfly init bash)"
or to ~.zshrc
eval "$(mcfly init zsh)"
Finally, to link McFly to the shell, run
source ~/.bashrc
or
source ~/.zshrc
In both cases, finish by importing the shell history (Figure 4). On older or much-used machines, the process may take several minutes.

At this point, McFly is ready to run, but you may want to configure it in ~/.bashrc
or ~/.zshrc
with the options shown in Table 1.
Table 1
McFly Options
export MCFLY_LIGHT=TRUE |
Sets McFly to run in Light mode rather than the default Dark mode. |
export MCFLY_KEY_SCHEME=vim |
Sets McFly to use Vim key commands rather than the default Emacs. |
export MCFLY_FUZZY=true |
Results display related terms, not just exact matches. This field can increase the chance of finding results, but at the cost of more results to scroll through. |
export MCFLY_INTERFACE_VIEW=BOTTOM |
Places titlebar menu at the bottom of the screen. |
export MCFLY_DISABLE_MENU=TRUE |
The titlebar menu is not displayed. |
export MCFLY_RESULTS=50 |
Limits the number of results displayed. By default, only the top dozen results display. |
export MCFLY_HISTORY_LIMIT=5000 |
Limits the number of listings in McFly's history. |
export MCFLY_RESULTS_SORT=LAST_RUN or MCFLY_RESULTS_SORT=RANK |
Displays results according to the time run or by the rank assigned by McFly. |
Running McFly
McFly's basic syntax for searching is simple:
McFly search STRING
The basic navigation appears in the titlebar of the results page (see Table 2).
Table 2
Navigating McFly Results
Enter |
Run the command highlighted by the arrow key. |
Tab |
Edit a command before running it. |
F1 |
Sort by time, rather than rank. This is the default, so it has no effect unless MCFLY_RESULTS_SORT=RANK is set (see Table 1). |
F2 |
Delete the selected command from McFly's history. Useful for improving results. |
Esc |
Closes result page and returns to the command prompt. |
You can also display McFly's complete history and scroll through it with the up and down arrow keys. Using the arrow keys is usually the least effective way to use McFly, but it is probably the most common way to access history when you are using the same command several times in a row. Providing this functionality makes McFly a complete replacement for history
.
Results may change depending on the directory from which McFly is run, which can return more accurate results, but can also confuse users or complicate results. Similarly, if results are set to display in priority, a previously selected command is given priority, while a command that results in an error is not displayed or given lower priority. As you continue to use McFly, the results should improve as McFly adjusts to your use of commands. The search
sub-command can take the option --fuzzy
(-f
) NUMBER
for a fuzzy search and --results
(-r
) NUMBER
to specify the maximum number of results. In addition, --output-selection
(-o
) PATH
saves the results to a file.
Many users may only use the search
sub-command. However, McFly also supports other sub-commands, although they are not documented by any man page, only by brief entries accessed from the --help SUB-COMMAND
option. The add
sub-command can add to the history, using --dir
(-d
) to specify where the command was run, --exit
(-e
) EXIT-CODE
to specify an exit code, and --when
(-w
) to set when the command was run. Similarly, move
can specify an old directory (OLD_DIR_PATH
) and a new one (NEW_DIR_PATH
) in that order. The sub-commands init
and train
are also available for developers, but appear to be undocumented. However, the other sub-commands can be used by users to assist McFly in improving its search results.
Is McFly Worth Using?
At least initially, algorithms that can be trained must be taken on faith. All I can say with confidence is that several weeks of semi-regular use did not noticeably improve McFly's results. However, such limited, inconsistent trials are inconclusive. It seems likely that heavier use or a longer trial period would produce clearer results. Documentation on how to use the train
sub-command would probably be useful as well.
However, even without a learning algorithm, McFly has decided benefits over history
. Not only is McFly customizable, both through its environmental variables and the add
and move
sub-commands, but its simple interface makes it much easier to use than history. Even with the verdict still out about its learning capabilities, McFly's design makes it one of the new breed of modern Linux commands that are replacing so many of the venerable ones.
Infos
- McFly: https://github.com/cantino/mcfly
- Installing with Homebrew: https://unixcop.com/how-to-install-mcfly-on-linux/
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
Red Hat Migrates RHEL from Xorg to Wayland
If you've been wondering when Xorg will finally be a thing of the past, wonder no more, as Red Hat has made it clear.
-
PipeWire 1.0 Officially Released
PipeWire was created to take the place of the oft-troubled PulseAudio and has finally reached the 1.0 status as a major update with plenty of improvements and the usual bug fixes.
-
Rocky Linux 9.3 Available for Download
The latest version of the RHEL alternative is now available and brings back cloud and container images for ppc64le along with plenty of new features and fixes.
-
Ubuntu Budgie Shifts How to Tackle Wayland
Ubuntu Budgie has yet to make the switch to Wayland but with a change in approaches, they're finally on track to making it happen.
-
TUXEDO's New Ultraportable Linux Workstation Released
The TUXEDO Pulse 14 blends portability with power, thanks to the AMD Ryzen 7 7840HS CPU.
-
AlmaLinux Will No Longer Be "Just Another RHEL Clone"
With the release of AlmaLinux 9.3, the distribution will be built entirely from upstream sources.
-
elementary OS 8 Has a Big Surprise in Store
When elementary OS 8 finally arrives, it will not only be based on Ubuntu 24.04 but it will also default to Wayland for better performance and security.
-
OpenELA Releases Enterprise Linux Source Code
With Red Hat restricting the source for RHEL, it was only a matter of time before those who depended on that source struck out on their own.
-
StripedFly Malware Hiding in Plain Sight as a Cryptocurrency Miner
A rather deceptive piece of malware has infected 1 million Windows and Linux hosts since 2017.
-
Experimental Wayland Support Planned for Linux Mint 21.3
As with most Linux distributions, the migration to Wayland is in full force. While some distributions have already made the move, Linux Mint has been a bit slower to do so.