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
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.