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
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4