Replacing history with McFly
Command Line – McFly
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
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.