Communitygithub.com

G1Joshi/Agent-Skills

Zsh 专家辅助:涵盖 shell 自定义、Oh My Zsh 插件、Zinit 插件管理器、提示符工程(Starship/Powerlevel10k)以及 shell 脚本编写。适用于配置 .zshrc、编写 Zsh 自动化脚本、优化 shell 启动时间或配置 Tab 补全时使用。

Agent-Skills 是什么?

该技能聚焦于 Zsh shell 的专业配置与优化,旨在帮助开发者构建高性能、高度定制化的交互式终端环境。它提供了从最小化 `.zshrc` 基础配置到高级异步插件加载(如使用 Zinit)、提示符工程(Starship/Powerlevel10k)以及健壮的 shell 脚本编写实践的全套指南。主要支持的平台包括 macOS 和 Linux 服务器,适用于需要加速 shell 启动速度(目标是低于 20 毫秒)、实现智能补全和历史搜索、以及管理复杂开发环境的场景。技能文档中包含了具体的配置代码片段、常见模式(如高速插件加载、安全凭证管理)、最佳实践(如编译 `compdump` 文件)和故障排查表,使得 AI 智能体能够直接生成或调整生产级的 Zsh 配置。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/tools/zsh

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Zsh

Zsh 是 macOS 的默认 shell。它具有高度的可定制性,并且与 Bash 兼容。

何时使用

  • 高生产力交互式 Shell:交互式自动补全、模糊导航、历史搜索以及分支指示器。
  • 现代 CLI 插件生态系统:通过 zsh-autosuggestions、zsh-syntax-highlighting 和 Starship 提示符加速 shell 工作流。
  • 健壮的 Shell 脚本编写:使用数组操作和 globbing 编写兼容 POSIX 以及 Zsh 扩展的自动化脚本。
  • 企业环境管理:在 macOS 和 Linux 服务器上管理 SDK 版本、PATH 导出和别名。

快速开始

1. 最小的 ~/.zshrc 配置

# 历史记录配置
HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=50000
setopt HIST_IGNORE_DUPS
setopt SHARE_HISTORY

# 按键绑定 (emacs 模式)
bindkey -e

# 自动补全
autoload -Uz compinit && compinit

# 别名
alias ll="ls -lah"
alias g="git"
alias gs="git status -sb"

2. 基准测试启动时间

# 分析 Zsh 启动持续时间
time zsh -i -c exit

核心概念

高速现代 Zshrc (~/.zshrc)

配置低于 20ms 的 shell 启动、智能补全和历史记录:

# ~/.zshrc
# 历史记录配置
HISTFILE="$HOME/.zsh_history"
HISTSIZE=50000
SAVEHIST=50000
setopt EXTENDED_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_VERIFY
setopt SHARE_HISTORY

# 目录导航选项
setopt AUTO_CD
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT

# 快速补全系统 (带缓存)
autoload -Uz compinit
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)
if [ $(date +'%j') != $updated_at ]; then
  compinit -i
else
  compinit -C -i
fi

# 现代按键绑定:历史搜索
bindkey -e
bindkey '^[[A' history-search-backward
bindkey '^[[B' history-search-forward

# 初始化 Starship 提示符 (如果已安装)
if command -v starship &> /dev/null; then
  eval "$(starship init zsh)"
fi

无重型框架的轻量级插件加载

直接加载自动建议和语法高亮:

# 克隆插件到 ~/.zsh/plugins/
# git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/plugins/zsh-autosuggestions
# git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.zsh/plugins/zsh-syntax-highlighting

source ~/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source ~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# 配置建议文字颜色
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'

高级 Zsh Globbing 和参数展开

利用递归 globbing 和修饰符:

# 列出过去 24 小时内修改过的所有 TypeScript 文件
ls -lh **/*.ts(m-1)

# 递归删除所有空目录
rmdir -p **/*(/^F) 2>/dev/null

# 仅选择 bin/ 中可执行文件
chmod +x bin/*(*)

常见模式

使用 Zinit 实现高速插件加载

问题:Oh My Zsh 因大量立即加载导致启动时间长达数百毫秒。 解决方案:使用 Zinit 的 turbo 模式(延迟加载)。

# 如果 Zinit 缺失则安装
source ~/.local/share/zinit/zinit.git/zinit.zsh

# 异步 turbo 加载语法高亮和自动建议
zinit wait lucid for \
  atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
    zdharma-continuum/fast-syntax-highlighting \
  atload"_zsh_autosuggest_start" \
    zsh-users/zsh-autosuggestions \
  blockf \
    zsh-users/zsh-completions

健壮的 Shell 脚本函数

问题:编写具有选项解析和错误处理的可重用 shell 函数。 解决方案:使用标准的 Zsh 参数展开。

# mkcd: 创建目录并进入
mkcd() {
  if [[ -z "$1" ]]; then
    echo "用法: mkcd <dir>" >&2
    return 1
  fi
  mkdir -p "$1" && cd "$1"
}

最佳实践 (2026)

  • 应做:将 ~/.zcompdump 编译为字节码文件 (compdump.zwc) 以加速 shell 启动时间。
  • 应做:设置 setopt SHARE_HISTORY 以同步所有活动终端标签页的命令历史。
  • 应做:使用 Starship 或精简的内置提示符,而非臃肿的旧式提示符主题。
  • 应做:通过在 ~/.zshrc 的开头和结尾使用 zmodload zsh/zprof 来分析启动延迟。
  • 不应做:使用庞大臃肿的框架配置(单片式 Oh-My-Zsh 配置)并加载数十个不需要的插件。
  • 不应做:在 ~/.zshrc 中以明文存储云凭证、API 令牌或密钥;应使用私有的 .env 文件或密钥保管库。
  • 不应做:在每个交互式 shell 启动时同步运行慢速的外部命令(如 nvm、brew doctor)。

故障排查

错误 / 症状原因解决方案
编辑 .zshrc 后出现 zsh: command not found: ....zshrc 中存在语法错误,或 $PATH 赋值被覆盖而非追加正确追加路径:export PATH="$HOME/bin:$PATH" 并运行 source ~/.zshrc。
zsh compinit: insecure directories, run compaudit/usr/local/share/zsh 目录权限不安全运行 `compaudit
Zsh 启动非常缓慢 (> 500ms)同步执行 nvm 或重型插件初始化对 nvm 使用惰性加载,或在 .zshrc 开头用 zmodload zsh/zprof,末尾用 zprof 进行性能分析。

参考

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

G1Joshi/Agent-Skills

Expert Dask distributed computing assistance covering Dask DataFrames, Arrays, Futures, and cluster scaling. Use when analyzing datasets too large for pandas on a single machine or multi-node cluster.

G1Joshi/Agent-Skills

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert K9s CLI assistance covering terminal Kubernetes cluster navigation, real-time log streaming, port forwarding, and pod debugging. Use when managing and troubleshooting Kubernetes clusters with speed.

G1Joshi/Agent-Skills

Expert SWC assistance covering high-performance Rust-based JavaScript/TypeScript compilation, .swcrc configuration, Jest testing via @swc/jest, and minification. Use when replacing Babel with SWC for faster builds, accelerating test execution, or compiling modern ECMAScript features.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

相关技能