mcfly – 采用小型神经网络智能化的 Shell 命令行历史搜索工具

McFly 能帮你快速找到需要的命令。它不仅支持模糊搜索,还能根据上下文智能排序搜索结果,让你一击即中,大大提升工作效率。想不起命令了? 没关系,McFly 能帮你回忆。它会根据你当前的工作目录和历史命令,为你提供最相关的建议,让你快速完成任务。

file

功能特点

  • ctrl-r键被重设为激活全屏反向历史搜索,结合小型神经网络优化排序。
  • shell历史被增强,命令的退出状态、时间戳和执行目录都会记录到SQLite数据库中。
  • 保留普通的shell历史文件,方便随时停止使用McFly。
  • 全程支持Unicode。
  • 简单操作即可从McFly数据库和shell历史文件中清理任何历史项目。
  • 设计为未来可扩展到其他shell。
  • 采用Rust编写,运行高效且安全。
  • 搜索时可以使用 % 来匹配任意字符数。

命令优先级

McFly 的核心特色是通过小型神经网络实时运行的智能命令优先级排序,目的是让你希望执行的命令总是位于顶部建议中。在推荐命令时,McFly 会考量:

  • 你在哪个目录下执行的命令。你未来可能会在同一目录下再次运行该命令。
  • 在该命令之前输入的命令(即执行上下文)。
  • 该命令被执行的频率。
  • 上次执行该命令的时间。
  • 是否曾在 McFly 中选中过该命令。
  • 命令的历史退出状态。你大概不希望再次执行之前失败的命令。

安装指南

使用 Homebrew 安装(适用于 macOS 或 Linux)

安装 McFly:

brew install mcfly

~/.bashrc~/.zshrc~/.config/fish/config.fish 文件末尾添加以下内容:

Bash:

eval "$(mcfly init bash)"

Zsh:

eval "$(mcfly init zsh)"

Fish:

mcfly init fish | source

运行 . ~/.bashrc. ~/.zshrcsource ~/.config/fish/config.fish,或者重启你的终端模拟器。

用 Homebrew 卸载

移除 McFly:

brew uninstall mcfly

~/.bashrc~/.zshrc~/.config/fish/config.fish 中移除添加的行。

使用 MacPorts 安装(仅适用于 macOS)

更新端口库:

sudo port selfupdate

安装 McFly:

sudo port install mcfly

~/.bashrc~/.zshrc~/.config/fish/config.fish 文件末尾添加以下内容:

Bash:

eval "$(mcfly init bash)"

Zsh:

eval "$(mcfly init zsh)"

Fish:

mcfly init fish | source

运行 . ~/.bashrc. ~/.zshrcsource ~/.config/fish/config.fish,或者重启你的终端模拟器。

用 MacPorts 卸载

移除 McFly:

sudo port uninstall mcfly

~/.bashrc~/.zshrc~/.config/fish/config.fish 中移除添加的行。

使用安装脚本安装(macOS 或 Linux)

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

(如果当前用户没有编辑 /usr/local/bin 的权限,请使用 sudo sh -s。)

~/.bashrc~/.zshrc~/.config/fish/config.fish 文件末尾添加以下内容:

Bash:

eval "$(mcfly init bash)"

Zsh:

eval "$(mcfly init zsh)"

Fish:

mcfly init fish | source

运行 . ~/.bashrc. ~/.zshrcsource ~/.config/fish/config.fish,或者重启你的终端模拟器。

从 GitHub 手动安装(macOS 或 Linux)

从 GitHub 下载最新版本的 McFly。

将其安装到你的 $PATH 中的一个目录(例如,你可以在 ~/bin 创建一个目录,将 McFly 复制到该目录,并在 .bashrc/.zshrc 中添加 export PATH="$PATH:$HOME/bin",或者在 Fish 中运行 set -Ua fish_user_paths "$HOME/bin")。

~/.bashrc~/.zshrc~/.config/fish/config.fish 文件末尾添加以下内容:

Bash:

eval "$(mcfly init bash)"

Zsh:

eval "$(mcfly init zsh)"

Fish:

mcfly init fish | source

运行 . ~/.bashrc. ~/.zshrcsource ~/.config/fish/config.fish,或者重启你的终端模拟器。

从源代码手动安装(macOS、Linux 或 Windows)

安装 Rust 1.40 或更高版本。

运行 git clone https://github.com/cantino/mcfly,然后 cd mcfly

运行 cargo install --path .

确保 ~/.cargo/bin 在你的 $PATH 中。

~/.bashrc~/.zshrc~/.config/fish/config.fish 或 PowerShell $PROFILE 文件末尾添加以下内容:

Bash:

eval "$(mcfly init bash)"

Zsh:

eval "$(mcfly init zsh)"

Fish:

mcfly init fish | source

PowerShell Core(pwsh):

Invoke-Expression -Command $(mcfly init powershell | out-string)

运行 . ~/.bashrc. ~/.zshrcsource ~/.config/fish/config.fish. $PROFILE 或者重启你的终端模拟器。

使用 Zinit 安装

在你的 ~/.zshrc 中添加以下代码:

zinit ice lucid wait"0a" from"gh-r" as"program" atload'eval "$(mcfly init zsh)"'
zinit light cantino/mcfly

这将下载并安装 McFly,并在提示后执行 $(mcfly init zsh)

官方链接

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注