fz 项目使用教程
fz.sh 项目地址: https://gitcode.com/gh_mirrors/fz/fz
1. 项目介绍
fz 是一个命令行 shell 插件,它为 z 命令的目录跳转功能添加了模糊搜索的自动补全功能。用户可以在 Bash 和 zsh 环境中轻松地跳转到历史访问过的目录。该插件不需要任何额外的键绑定,并且建立在 z 和 fzf 的基础上。
2. 项目快速启动
以下是在 macOS 和 Ubuntu 系统上快速启动 fz 项目的步骤。
macOS
安装 fzf:
brew install fzf
下载 z 和 fz:
mkdir -p ~/.bash_completion.d
curl -o ~/.bash_completion.d/z https://raw.githubusercontent.com/rupa/z/master/z.sh
curl -o ~/.bash_completion.d/fz.sh https://raw.githubusercontent.com/changyuheng/fz/master/fz.sh
将以下内容添加到 ~/.bashrc:
if [ -d ~/.bash_completion.d ]; then
then
for file in ~/.bash_completion.d/*
do
. $file
done
fi
Ubuntu
安装 fzf:
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
下载 z 和 fz:
mkdir -p ~/.bash_completion.d
curl -o ~/.bash_completion.d/z https://raw.githubusercontent.com/rupa/z/master/z.sh
curl -o ~/.bash_completion.d/fz.sh https://raw.githubusercontent.com/changyuheng/fz/master/fz.sh
将以下内容添加到 ~/.bashrc:
if [ -d ~/.bash_completion.d ]; then
for file in ~/.bash_completion.d/*
do
. $file
done
fi
应用配置:
source ~/.bashrc
3. 应用案例和最佳实践
使用 fz 插件时,您可以简单地输入 z 命令,然后按下 Tab 键进行自动补全。以下是一些使用场景:
快速跳转到最近访问的目录:
z [dir name slug]
仅从当前工作目录开始搜索:
zz [dir name slug]
使用 Tab、Shift-Tab、Ctrl-n、Ctrl-p、Ctrl-j 或 Ctrl-k 在补全项之间导航。
4. 典型生态项目
fz 插件依赖于以下典型生态项目:
z:一个快速跳转目录的 shell 插件。fzf:一个用于命令行的模糊查找工具。oh-my-zsh:一个流行的 zsh 配置框架,包含许多插件和主题。
确保在使用 fz 之前安装这些依赖项目。
fz.sh 项目地址: https://gitcode.com/gh_mirrors/fz/fz