McFly - fly through your shell history

Overview

Build Status

McFly - fly through your shell history

screenshot

McFly replaces your default ctrl-r shell history search with an intelligent search engine that takes into account your working directory and the context of recently executed commands. McFly's suggestions are prioritized in real time with a small neural network.

TL;DR: an upgraded ctrl-r where history results make sense for what you're working on right now.

Features

  • Rebinds ctrl-r to bring up a full-screen reverse history search prioritized with a small neural network.
  • Augments your shell history to track command exit status, timestamp, and execution directory in a SQLite database.
  • Maintains your normal shell history file as well so that you can stop using McFly whenever you want.
  • Unicode support throughout.
  • Includes a simple action to scrub any history item from the McFly database and your shell history files.
  • Designed to be extensible for other shells in the future.
  • Written in Rust, so it's fast and safe.
  • You can type % to match any number of characters when searching.

Prioritization

The key feature of McFly is smart command prioritization powered by a small neural network that runs in real time. The goal is for the command you want to run to always be one of the top suggestions.

When suggesting a command, McFly takes into consideration:

  • The directory where you ran the command. You're likely to run that command in the same directory in the future.
  • What commands you typed before the command (e.g., the command's execution context).
  • How often you run the command.
  • When you last ran the command.
  • If you've selected the command in McFly before.
  • The command's historical exit status. You probably don't want to run old failed commands.

Installation

Install with Homebrew (on OS X or Linux)

  1. Install the tap:

    brew tap cantino/mcfly
  2. Install mcfly:

    brew install cantino/mcfly/mcfly
  3. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  4. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Uninstalling with Homebrew

  1. Remove mcfly:
    brew uninstall mcfly
  2. Remove the tap:
    brew untap cantino/mcfly
  3. Remove the lines you added to ~/.bashrc / ~/.zshrc / ~/.config/fish/config.fish.

Install with MacPorts (on OS X)

  1. Update the ports tree

    sudo port selfupdate
  2. Install mcfly:

    sudo port install mcfly
  3. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file, as appropriate:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  4. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Uninstalling with MacPorts

  1. Remove mcfly:
    sudo port uninstall mcfly
  2. Remove the lines you added to ~/.bashrc / ~/.zshrc / ~/.config/fish/config.fish.

Installing using our install script

  1. curl -LSfs https://raw.githubusercontent.com/cantino/mcfly/master/ci/install.sh | sh -s -- --git cantino/mcfly

  2. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file, respectively:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  3. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Installing manually from GitHub

  1. Download the latest release from GitHub.

  2. Install to a location in your $PATH. (For example, you could create a directory at ~/bin, copy mcfly to this location, and add export PATH="$PATH:$HOME/bin" to your .bashrc / .zshrc, or run set -Ua fish_user_paths "$HOME/bin" for fish.)

  3. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file, respectively:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  4. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Install manually from source

  1. Install Rust 1.40 or later

  2. Run git clone https://github.com/cantino/mcfly and cd mcfly

  3. Run cargo install --path .

  4. Ensure ~/.cargo/bin is in your $PATH.

  5. Add the following to the end of your ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish file, respectively:

    Bash:

    eval "$(mcfly init bash)"

    Zsh:

    eval "$(mcfly init zsh)"

    Fish:

    mcfly init fish | source
  6. Run . ~/.bashrc / . ~/.zshrc / source ~/.config/fish/config.fish or restart your terminal emulator.

Install by Zinit

  • Add below code to your zshrc.

    zinit ice lucid wait"0a" from"gh-r" as"program" atload'eval "$(mcfly init zsh)"' 
    zinit light cantino/mcfly 
  • It will download mcfly and install for you.

  • $(mcfly init zsh) will be executed after prompt

iTerm2

To avoid McFly's UI messing up your scrollback history in iTerm2, make sure this option is unchecked:

iterm2 UI instructions

Settings

A number of settings can be set via environment variables. To set a setting you should add the following snippets to your ~/.bashrc / ~/.zshrc / ~/.config/fish/config.fish.

Light Mode

To swap the color scheme for use in a light terminal, set the environment variable MCFLY_LIGHT.

bash / zsh:

export MCFLY_LIGHT=TRUE

fish:

set -gx MCFLY_LIGHT TRUE

Tip: on macOS you can use the following snippet for color scheme to be configured based on system-wide settings:

bash / zsh:

/dev/null)" != "Dark" ]]; then export MCFLY_LIGHT=TRUE fi">
if [[ "$(defaults read -g AppleInterfaceStyle 2&>/dev/null)" != "Dark" ]]; then
    export MCFLY_LIGHT=TRUE
fi

VIM Key Scheme

By default Mcfly uses an emacs inspired key scheme. If you would like to switch to the vim inspired key scheme, set the environment variable MCFLY_KEY_SCHEME.

bash / zsh:

export MCFLY_KEY_SCHEME=vim

fish:

set -gx MCFLY_KEY_SCHEME vim

Fuzzy Searching

To enable fuzzy searching, set MCFLY_FUZZY to an integer. 0 is off; higher numbers weight toward shorter matches. Values in the 2-5 range get good results so far; try a few and report what works best for you!

bash / zsh:

export MCFLY_FUZZY=2

fish:

set -gx MCFLY_FUZZY 2

Results Count

To change the maximum number of results shown, set MCFLY_RESULTS (default: 10).

bash / zsh:

export MCFLY_RESULTS=50

fish:

set -gx MCFLY_RESULTS 50

Interface view

To change interface view, set MCFLY_INTERFACE_VIEW (default: TOP). Available options: TOP and BOTTOM

bash / zsh:

export MCFLY_INTERFACE_VIEW=BOTTOM

fish:

set -gx MCFLY_INTERFACE_VIEW BOTTOM

Disable menu interface

To disable the menu interface, set the environment variable MCFLY_DISABLE_MENU.

bash / zsh:

export MCFLY_DISABLE_MENU=TRUE

fish:

set -gx MCFLY_DISABLE_MENU TRUE

Results sorting

To change the sorting of results shown, set MCFLY_RESULTS_SORT (default: RANK). Possible values RANK and LAST_RUN

bash / zsh:

export MCFLY_RESULTS_SORT=LAST_RUN

fish:

set -gx MCFLY_RESULTS_SORT LAST_RUN

Database Location

McFly stores its SQLite database in the standard location for the OS. On OS X, this is in ~/Library/Application Support/McFly and on Linux it is in $XDG_DATA_DIR/mcfly/history.db (default would be ~/.local/share/mcfly/history.db). For legacy support, if ~/.mcfly/ exists, it is used instead.

Slow startup

If you have a very large history database and you notice that McFly launches slowly, you can set MCFLY_HISTORY_LIMIT to something like 10000 to limit how many records are considered when searching. In this example, McFly would search only the latest 10,000 entries.

Possible Future Features

  • Add a screencast to README.
  • Learn common command options and autocomplete them in the suggestion UI?
  • Sort command line args when coming up with the template matching string.
  • Possible prioritization improvements:
    • Cross validation & explicit training set selection.
    • Learn command embeddings

Development

Contributing

Contributions and bug fixes are encouraged! However, we may not merge PRs that increase complexity significantly beyond what is already required to maintain the project. If you're in doubt, feel free to open an issue and ask.

Running tests

cargo test

Releasing (notes for @cantino)

  1. Edit Cargo.toml and bump the version.
  2. Edit CHANGELOG.txt
  3. Run cargo clippy and cargo fmt.
  4. Recompile (cargo build).
  5. git add -p
  6. git ci -m 'Bumping to vx.x.x'
  7. git tag vx.x.x
  8. git push origin head --tags
  9. Let the build finish.
  10. Edit the new Release on Github.
  11. Edit pkg/brew/mcfly.rb and update the version and SHAs. (shasum -a 256 ...)
  12. Edit ../homebrew-mcfly/pkg/brew/mcfly.rb too.
  13. cp pkg/brew/mcfly.rb ../homebrew-mcfly/pkg/brew/mcfly.rb
  14. Compare with diff ../homebrew-mcfly/pkg/brew/mcfly.rb ../mcfly/pkg/brew/mcfly.rb ; diff ../homebrew-mcfly/HomebrewFormula/mcfly.rb ../mcfly/HomebrewFormula/mcfly.rb
  15. git add -p && git ci -m 'Update homebrew' && git push
  16. cd ../homebrew-mcfly && git add -p && git ci -m 'Update homebrew' && git push && cd ../mcfly
  17. cargo publish
Comments
  • Add forward-compatibility check for database schema

    Add forward-compatibility check for database schema

    This adds an extra safety check in case mcfly encounters a schema newer than it knows how to deal with.

    The main motivation is to provide safety for users of my mcfly-fzf companion tool. This way users will see an obvious error if the DB schema used by their mcfly binary somehow is off from the schema used by their mcfly-fzf binary.

    opened by bnprks 0
  • Hanging after each command with zsh

    Hanging after each command with zsh

    Hi

    I am using this with zinit with the setup commands in the readme, and have discovered that, with a db size of around 25,000, every command hangs for about 3-5 seconds. I can't really figure out why, since it running mcfly add directly runs in a few milliseconds, but I have had to disable the plugin for now.

    Is this known behaviour?

    Alex

    opened by arlyon 3
  • Error on upgrading mcfly to 0.7.0: The argument '--append-to-histfile ' requires a value but none was supplied

    Error on upgrading mcfly to 0.7.0: The argument '--append-to-histfile ' requires a value but none was supplied

    Using brew to upgrade, macOS 13.0.1 (Ventura)


    Sun Dec 11 12:50 PM jenett [~] $ mcfly search error: The argument '--append-to-histfile ' requires a value but none was supplied

    opened by joejenett 3
  • Feature Request: New way of displaying hotkeys

    Feature Request: New way of displaying hotkeys

    As more features for different hotkeys are being added in, eventually we will run out of screen real estate to display all hotkeys.

    Screenshot 2022-11-30 at 6 39 45 PM

    My first proposal is that we add a new hotkey that will open another termion alternate screen to display a table of hotkeys and their related action. Pressing the same hotkey will close this alternate screen and go back to the main McFly screen. My second proposal is that we remove all the hotkeys from the menu bar and create a fixed hotkey table at the bottom of the screen. The only issue I see with this one is we probably would need to look into removing MCFLY_INTERFACE_VIEW=BOTTOM. Also, the other caveat to this solution is displaying ALL hotkeys on the main screen will clutter the UI in the future if there are too many hotkeys.

    Upon further testing, the menubar will wrap text if it exceeds the terminal width. I mention this because this will cause any issue once the menubar exceeds two lines in length.

    Screenshot 2022-11-30 at 10 00 21 PM

    opened by navazjm 1
  • features: make selete history and copy

    features: make selete history and copy

    sometime ,I selete one command, just copy it. so, make new argu to copy command.

    and, the show line is littel zone image

    look this, more screen is not show, so make history to full screen

    opened by newyorkthink 0
Releases(v0.7.1)
Owner
Andrew Cantino
Ruby ◊ JS ◊ Rust ◊ Science ◊ Space ◊ InfoSec ◊ ML ◊ Greentech
Andrew Cantino
🐢 Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands

Atuin replaces your existing shell history with a SQLite database, and records additional context for your commands. Additionally, it provides optional and fully encrypted synchronisation of your history between machines, via an Atuin server.

Ellie Huxtable 4.6k Jan 1, 2023
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.

Connect quickly to your services ?? FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config. Instal

Julien 85 Dec 14, 2022
git-cliff can generate changelog files from the Git history by utilizing conventional commits as well as regex-powered custom parsers.⛰️

git-cliff can generate changelog files from the Git history by utilizing conventional commits as well as regex-powered custom parsers. The changelog template can be customized with a configuration file to match the desired format.

Orhun Parmaksız 5k Jan 9, 2023
Simple calculator REPL, similar to bc(1), with syntax highlighting and persistent history

eva simple calculator REPL, similar to bc(1), with syntax highlighting and persistent history installation Homebrew $ brew install eva crates.io $ car

Akshay 632 Jan 4, 2023
Terminal UI for erhanbaris/smartcalc, a new way to do calculations on-the-fly

smartcalc-tui Terminal UI for erhanbaris/smartcalc, a new way to do calculations on-the-fly. From the README: Do your calculation on text based querie

Aaron Ross 12 Sep 14, 2022
An enhanced history(1) for bash

history This is a replacement for the history builtin in bash. It has a couple of additional features that relative to the one included with bash: Con

Robert T. McGibbon 4 Aug 25, 2022
🗄️ A simple (and safe!) to consume history of Client and Studio deployment versions.

??️ Roblox Version Archive A simple (and safe!) to consume history of Client and Studio deployment versions. About Parsing Roblox's DeployHistory form

Brooke Rhodes 4 Dec 28, 2022
Shell scripting that will knock your socks off

atom Shell scripting that will knock your socks off. NOTE: Click the image above for a video demonstration.

adam mcdaniel 256 Dec 14, 2022
Explore from the safety of your shell

turtlescan Explore from the safety of your shell Installation: cargo install turtlescan tui Starts a little tui which connects to your JSON-RPC server

Brian Cloutier 4 Sep 13, 2022
Raw C Shell: interact with your operating system using raw C code, because why not?

rcsh Raw C Shell is a minimalist shell with no built in commands. You write entirely in C code and use return; to execute your code. Unlike that silly

null 4 Feb 7, 2023
Ask ChatGPT for a shell script, code, or anything, directly from your terminal 🤖🧠👨‍💻

ShellGPT Ask ChatGPT for a shell script, code, or anything, directly from your terminal ?? ?? ??‍?? Demo Install The binary is named gpt when installe

null 4 May 15, 2023
Animated app icons in your Dock that can run an arbitrary shell script when clicked.

Live App Icon for Mac Animated app icons in your Dock that can run an arbitrary shell script when clicked. Requirements macOS 13 (Ventura) or higher X

Daichi Fujita 13 Jun 8, 2023
This utility traverses through your filesystem looking for open-source dependencies that are seeking donations by parsing README.md and FUNDING.yml files

This utility traverses through your filesystem looking for open-source dependencies that are seeking donations by parsing README.md and FUNDING.yml files

Mufeed VH 38 Dec 30, 2022
A new type of shell

A new type of shell

Nushell Project 22.5k Jan 8, 2023
a cute shell thingy that written in rust

a cute shell thingy that written in rust

奥田 龍馬 12 Dec 29, 2021
A shell for research papers

Reason: A Shell for Research Papers Did I ever read this paper? Which OSDI 2021 papers did I read? Which ones have the word 'Distributed' in their tit

Jae-Won Chung 121 Nov 27, 2022
dune - A shell by the beach!

dune - A shell by the beach!

adam mcdaniel 640 Dec 29, 2022
A command-line shell like fish, but POSIX compatible.

A command-line shell like fish, but POSIX compatible.

Seiya Nuta 813 Dec 29, 2022
Zash - A Zuper Awesome Shell

Zash - A Zuper Awesome Shell Welcome to zash, its activily being developed and is not near a stable release. Installation Arch: yay -S zash Paru seem

Robiot 27 May 22, 2022