Communitygithub.com

G1Joshi/Agent-Skills

專業 Zsh 協助,涵蓋 shell 自訂、Oh My Zsh 外掛、Zinit 套件管理、提示字元工程(Starship/Powerlevel10k)及 shell 腳本。適合在設定 .zshrc、撰寫 Zsh 自動化腳本、最佳化 shell 啟動時間或設定 Tab 補全時使用。

Agent-Skills 是什麼?

此技能提供關於 Zsh 的深度專業知識,包含 shell 自訂、外掛管理、提示字元工程以及腳本撰寫。它不僅說明如何設定高效能的 `~/.zshrc`(啟動時間低於 20 毫秒),還指導如何輕量化載入 `zsh-autosuggestions` 與 `zsh-syntax-highlighting` 等外掛,並能善用 Zsh 特有的遞迴 globbing 與參數展開功能。此外,技能涵蓋了使用 Zinit 的 Turbo 模式達成非同步、延遲載入外掛,以及如何撰寫包含錯誤處理的強健 shell 函式。此技能適用於 macOS 與 Linux 環境,支援 Oh My Zsh 與 Zinit 等框架,並提供 2026 年的最佳實踐與常見問題排解表,幫助開發者最佳化互動式 shell 體驗與撰寫可靠的自動化腳本。

相容平台~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 腳本:撰寫 POSIX 相容及 Zsh 擴充的自動化腳本,運用陣列操作與 globbing 功能。
  • 企業環境管理:在 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 啟動時間
zmodload zsh/zprof
time zsh -i -c exit

核心概念

高速現代 Zshrc (~/.zshrc)

設定低於 20 毫秒的 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 <目錄>" >&2
    return 1
  fi
  mkdir -p "$1" && cd "$1"
}

最佳實踐 (2026)

  • 請務必 將 ~/.zcompdump 編譯為位元組碼檔案 (compdump.zwc),以加速 shell 啟動時間。
  • 請務必 設定 setopt SHARE_HISTORY 以同步所有作用中終端機頁籤的指令歷史。
  • 請務必 使用 Starship 或精簡的原生提示字元,避免使用肥大過時的提示主題。
  • 請務必 使用 zmodload zsh/zprof 在 ~/.zshrc 的開頭和結尾進行啟動延遲分析。
  • 請勿 使用肥大、笨重的框架設定(如單體式 Oh-My-Zsh 設定)並載入數十個不需要的外掛。
  • 請勿 將純文字雲端憑證、API 權杖或機密資訊儲存在 ~/.zshrc 中;請使用私有的 .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].

相關技能