Fuzzy Shell Documentation
TIP
fuzzy_shell
缝合fd
和fzf
两个工具,易用性更强。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 ~/.bashrc
或source ~/.zshrc
使配置生效。- 输入
fj
或fuzzy --jump
即可使用模糊跳转功能。
1.2 依赖要求
- 对于
MacOS
用户,需要预装brew
。 zsh
最低版本要求为5.2.0
,bash
最低版本要求为4.4.0
。- 推荐使用包管理器预先安装
fd
和fzf
,如果没有预装,也可以选用fuzzy_shell
自带的fd
和fzf
二进制文件。
2. 用法
- 您的
shell
配置文件(~/.bashrc
或~/.zshrc
)中,已经添加了fuzzy_shell
的alias
,可以直接使用。 - 输入
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
, 会调用fd
和fzf
工具,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
会调用fzf
和history
,history
用于检索历史记录,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
- 支持
bash
和zsh
。 bash
最低版本要求为4.4.0
,zsh
最低版本要求为5.2.0
- 目前不支持
fish
,未来也不考虑支持fish