Skip to content

Fuzzy Shell Documentation

TIP

  1. fuzzy_shell 缝合 fdfzf 两个工具,易用性更强。
  2. fuzzy_shell 具备模糊跳转、编辑、查找文件等功能。

1. 安装

1.1 Quick Start

sh
# clone the repo
git clone https://github.com/Albert26193/fuzzy-shell.git

# install on Linux
cd fuzzy-shell && sudo bash install/install.sh

# install on Mac (no root)
cd fuzzy-shell && bash install/install.sh
  • 安装完毕,如果看到 ~/.bashrc~/.zshrc 已经自动添加如下配置,即安装成功 🎉:
sh
# ~/.bashrc or ~/.zshrc

#------------------- fuzzy-shell -------------------
source "${HOME}/.fuzzy_shell/scripts/export.sh"
alias "fs"="fuzzy --search"
alias "fj"="fuzzy --jump"
alias "fe"="fuzzy --edit"
alias "fh"="fuzzy --history"
  • source ~/.bashrcsource ~/.zshrc 使配置生效。
  • 输入 fjfuzzy --jump 即可使用模糊跳转功能。

1.2 依赖要求

  • 对于 MacOS 用户,需要预装 brew
  • zsh 最低版本要求为 5.2.0, bash 最低版本要求为 4.4.0
  • 推荐使用包管理器预先安装 fdfzf,如果没有预装,也可以选用 fuzzy_shell 自带的 fdfzf 二进制文件。

2. 用法

  • 您的 shell 配置文件(~/.bashrc~/.zshrc)中,已经添加了 fuzzy_shellalias,可以直接使用。
  • 输入 fuzzy --help 查看帮助信息。
sh
# fuzzy --help
Usage: fuzzy [option] [args]
Options:
  -s, --search [keyword1] [keyword2] [keyword3], namely fuzzy search
  -H, --history                              , namely fuzzy history search
  -j, --jump [keyword1] [keyword2] [keyword3], namely fuzzy jump
  -e, --edit [keyword1] [keyword2] [keyword3], namely fuzzy edit
Details
  • 以下三个功能,即 fuzzy jump, fuzzy edit, fuzzy search, 会调用 fdfzf 工具,fd 用于搜索文件,fzf 用于交互式选择文件。
  • 索引范围、ignore 文件等,可以在 ~/.fuzzy_shell/config.env 中配置。
  • 路径参数无需精准匹配,只需模糊匹配即可。

2.1 fuzzy jump 模糊跳转

  • fuzzy jump 用于模糊跳转到指定目录,或指定文件所在目录。
sh
# fuzzy jump to the directory which contains 'keyword1' and 'keyword2', 'keyword3'
fuzzy --jump keyword1 keyword2 keyword3

2.2 fuzzy edit 模糊编辑

  • fuzzy edit 用于模糊编辑指定文件。
  • 编辑器默认为 vim,可以在 ~/.fuzzy_shell/config.env 中配置,比如 nvim 等。
sh
# fuzzy edit the file which contains 'keyword1' and 'keyword2', 'keyword3'
fuzzy --edit keyword1 keyword2 keyword3

2.3 fuzzy search 模糊搜索

  • fuzzy search 用于模糊搜索指定文件。
sh
# fuzzy search the file which contains 'keyword1' and 'keyword2', 'keyword3'
fuzzy --search keyword1 keyword2 keyword3
  • 可以将其返回结果作为参数传递给其他命令。比如,试图删除 my-path 目录下 some-file 文件:
sh
rm $(fuzzy --search my-path some-file)

# 如果在 shellrc(~/.zshrc or ~/.bashrc) 当中做了 alias,则可以简化为
rm $(fs my-path some-file)

Details
  • fuzzy history 会调用 fzfhistoryhistory 用于检索历史记录,fzf 用于交互式选择文件。

2.4 fuzzy history 模糊查找历史

  • fuzzy history 用于模糊查找当前 shell 历史记录。
  • 无需参数,直接调用即可。
sh
# fuzzy search the history
fuzzy --history

3. 配置

  • fuzzy_shell 的配置文件位于 ~/.fuzzy_shell/config.env,可以配置 fd 的搜索范围、ignore 文件等。

  • 可以配置 4 个参数:

    • fs_search_dir:搜索范围,即 fd 的搜索路径。
    • fs_search_ignore_dirs:忽略文件,即 fd 的忽略文件。
    • fs_preview:是否开启预览功能,一般建议开启,除非卡顿严重。
    • fs_editor:编辑器,即 fuzzy edit 的编辑器。
  • 默认配置如下:

sh
# ~/.fuzzy_shell/config.env
#!/bin/bash

# in which dir to search
fs_search_dirs=(
    "${HOME}"
    #"CodeSpace"
)

# within search range, which dir to ignore
fs_search_ignore_dirs=(
    "Downloads"
    "Desktop"
    "Documents"
    ".git"
    ".local"
    ".m2"
    ".gradle"
    ".wns"
    ".nvm"
    ".npm"
    ".nrm"
    ".red-hat"
    ".oh-my-zsh"
    ".github"
    ".cache"
    ".cargo"
    ".rustup"
    ".vscode"
    ".vscode-insiders"
    ".vscode-server-insiders"
    ".vscode-server"
    ".vscode-oss"
    ".vscode-oss-insiders"
    "lib"
    "node_modules"
    "pkg"
    "bin"
    "dist"
    "pkgs"
    "from-github"
    "assets"
    "image"
    "images"
    "static"
    "data"
    "raycast"
    "zlt-*"
    "anaconda3"
    "miniconda3"
    "Applications"
    "Library"
    "Movies"
    "Music"
    "Pictures"
    "Public"
    "Remote"
    "Zotero"
    "EVPlayer2_download"
)

# search preview or not, true: preview | false: not preview
# if your machine is not powerful enough(RAM <= 1GiB), set it to false
# otherwise, set it to true(Recommend)
fs_search_preview=true
#fs_search_preview=false

fs_editor="vim"
# fs_editor="nvim"

4. 说明

4.1 卸载

  • 如果不再需要 fuzzy_shell,可以通过以下命令卸载:
sh
cd fuzzy_shell && sudo bash install/uninstall.sh
  • 卸载完毕,~/.bashrc~/.zshrc 中的配置需要手动清理。

4.2 支持的操作系统

  • 支持 x86_64 架构的 Linux 系统
  • 支持 x86_64/arm64 架构的 MacOS 系统
  • 目前测试通过的系统:
    • Ubuntu 18.04/22.04
    • CentOS 7/8
    • Debian 10/11/12

4.2 支持的 shell

  • 支持 bashzsh
  • bash 最低版本要求为 4.4.0zsh 最低版本要求为 5.2.0
  • 目前不支持 fish,未来也不考虑支持 fish

5. 未来计划

6. 致谢

  • 本项目仅仅只是数百行的 shell 小脚本,主要的工作需要感谢 fdfzf 两个工具的支持。
  • fd 项目链接: fd
  • fzf 项目链接: fzf