姚利锋
姚利锋
首页博客片段项目服务关于
☕
❤️
目录
  • 无目录
返回片段

发布于  2025 年 8 月 27 日,星期三

zoxide 与 fzf 、gh 快捷命令

AI 生成的摘要
此内容由 AI 生成

zoxide提供智能目录跳转功能,结合fzf的模糊搜索和GitHub CLI(gh)的命令行操作,实现高效的项目导航与仓库管理。通过集成这三个工具,开发者可以快速切换目录、搜索文件并执行GitHub操作,显著提升终端工作效率。文章包含配置指南和实际用例,帮助读者构建流畅的命令行工作流。

zoxide (智能目录跳转)

命令功能说明使用示例
z <关键字>核心功能。模糊匹配历史目录并跳转。z proj (跳转到最匹配的 "project" 目录)
z -i <关键字>交互式选择。当匹配项过多时,弹出列表让你选择。z -i doc (列出所有含 "doc" 的目录供选择)
z -q <关键字>查询记录。不跳转,只列出匹配的历史目录。z -q work (查看所有去过的 "work" 相关目录)
z -a <路径>手动添加。将一个路径手动添加到 zoxide 数据库。z -a /mnt/d/archive
z .. / z -cd 兼容。可以像 cd 一样用于返回上级或前一个目录。z .. (相当于 cd ..)

fzf (万物皆可搜)

快捷键 / 命令功能说明使用示例
Ctrl + R颠覆性历史命令搜索。(在终端任意位置按下) -> 输入 build 查找所有 build 命令
Ctrl + T插入文件/目录路径。vim (按下 Ctrl+T) -> 搜索 index.js 并插入路径
Alt + C快速 cd 到子目录。(在项目根目录按下) -> 搜索 components 并直接跳转
** + Tab模糊路径补全。cat **rc (按下 Tab) -> 列出 .zshrc, .npmrc 等供选择
`commandfzf`管道集成。fzf 的精髓,可与任何命令结合。
fkill (自定义)交互式杀死进程。一个非常实用的自定义别名。fkill (别名: ps -ef | fzf | awk '{print $2}' | xargs kill -9)

GitHub CLI (gh) 常用命令速查表

核心与认证 (Core & Auth)

命令 (Command)说明 (Description)示例 (Example)
gh auth login交互式登录你的 GitHub 账户。gh auth login
gh auth status查看当前的认证状态和活动的账户。gh auth status
gh auth logout登出你的 GitHub 账户。gh auth logout
gh config <command>管理 gh 的配置。gh config get git_protocol
gh alias <command>创建命令别名,简化常用操作。gh alias set co 'pr checkout'

仓库管理 (Repository)

命令 (Command)说明 (Description)示例 (Example)
gh repo clone <repo>克隆一个 GitHub 仓库。gh repo clone cli/cli
gh repo create <name>在你的 GitHub 账户下创建一个新的仓库。gh repo create my-new-project --public
gh repo fork <repo>Fork 一个仓库到你的账户下。gh repo fork cli/cli
gh repo view在终端中查看当前仓库的信息。gh repo view
gh repo view --web在浏览器中打开当前仓库页面。gh repo view -w
gh repo list [owner]列出某个用户或组织的仓库。gh repo list (列出自己的)
gh repo list github (列出 GitHub 组织的)

Pull Request (PR)

命令 (Command)说明 (Description)示例 (Example)
gh pr list列出当前仓库的 Pull Request。gh pr list
gh pr create从当前分支创建一个 Pull Request。gh pr create --title "My amazing feature" --body "Details..."
gh pr view <number>在终端中查看指定的 PR 详情。gh pr view 123
gh pr view --web <number>在浏览器中打开指定的 PR。gh pr view 123 -w
gh pr checkout <number>检出(切换到)指定的 PR 分支进行本地测试。gh pr checkout 123
gh pr checks查看当前分支或指定 PR 的 CI/CD 检查状态。gh pr checks
gh pr diff <number>查看指定 PR 的文件变更。gh pr diff 123
gh pr merge <number>合并一个 PR。gh pr merge 123 --squash --delete-branch
gh pr close <number>关闭一个 PR。gh pr close 123
gh pr reopen <number>重新打开一个已关闭的 PR。gh pr reopen 123
gh pr comment <number>在指定的 PR 下添加评论。gh pr comment 123 --body "Looks great!"

Issue 管理

命令 (Command)说明 (Description)示例 (Example)
gh issue list列出当前仓库的 Issue。gh issue list
gh issue create创建一个新的 Issue。gh issue create -t "Bug report" -b "Something is broken."
gh issue view <number>在终端中查看指定的 Issue。gh issue view 456
gh issue status查看与你相关的 Issue 状态。gh issue status
gh issue close <number>关闭一个 Issue。gh issue close 456
gh issue reopen <number>重新打开一个已关闭的 Issue。gh issue reopen 456

Gist 与 Codespaces

命令 (Command)说明 (Description)示例 (Example)
gh gist create <file>从文件创建一个 Gist (代码片段)。gh gist create my_script.py
gh gist list列出你的 Gist。gh gist list
gh gist view <id>查看一个 Gist。gh gist view <gist_id>
gh codespace list列出你的 Codespaces。gh codespace list
gh codespace ssh通过 SSH 连接到一个 Codespace。gh codespace ssh -c <codespace_name>
# Git# 构建工具# 版本控制# 代码质量# DevOps
返回片段