Communitygithub.com

Zshエキスパート支援

シェルカスタマイズ、Oh My Zshプラグイン、Zinitプラグインマネージャー、プロンプトエンジニアリング(Starship/Powerlevel10k)、シェルスクリプティングに関する専門的なZsh支援。.zshrcの設定、Zsh自動化スクリプトの作成、シェル起動時間の最適化、タブ補完の設定時に使用します。

Zshエキスパート支援 とは?

このスキルは、macOSおよびLinux環境におけるZshシェルの専門的な設定と最適化を支援します。.zshrcの高速化、プラグイン管理(Oh My Zsh、Zinit)、プロンプトカスタマイズ(Starship、Powerlevel10k)、シェルスクリプティングのベストプラクティスをカバーします。サブ20ミリ秒の起動時間を実現する設定方法や、非同期プラグインロードによる高速化、履歴検索や補完の最適化、堅牢なシェル関数の作成方法などを提供します。Claude CodeやCursor、CodexなどのAIエージェントが、ユーザーのターミナル環境を効率的にセットアップ・改善するための実践的なコードスニペットとトラブルシューティングガイドを備えています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/tools/zsh

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Zsh

ZshはmacOSのデフォルトシェルです。高度にカスタマイズ可能で、Bashとの互換性があります。

使用するタイミング

  • 高生産性インタラクティブシェル: 対話的な自動補完、ファジーナビゲーション、履歴検索、ブランチインジケーター。
  • モダンなCLIプラグインエコシステム: zsh-autosuggestions、zsh-syntax-highlighting、Starshipプロンプトによるシェルワークフローの高速化。
  • 堅牢なシェルスクリプティング: 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)

サブ20ミリ秒のシェル起動、スマート補完、履歴を設定:

# ~/.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グロビングとパラメータ展開

再帰的グロビングと修飾子を活用:

# 過去24時間に変更されたすべてのTypeScriptファイルをリスト
ls -lh **/*.ts(m-1)

# 空のディレクトリを再帰的に削除
rmdir -p **/*(/^F) 2>/dev/null

# bin/内の実行可能ファイルのみを選択
chmod +x bin/*(*)

一般的なパターン

Zinitによる高速プラグイン読み込み

問題: Oh My Zshの起動は、重い eager ロードのために数百ミリ秒かかる。 解決策: ターボモード(遅延読み込み)でZinitを使用する。

# Zinitがなければインストール
source ~/.local/share/zinit/zinit.git/zinit.zsh

# シンタックスハイライトとオートサジェストを非同期でターボロード
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

堅牢なシェルスクリプティング関数

問題: オプション解析とエラーハンドリングを備えた再利用可能なシェル関数を作成する。 解決策: 標準のZshパラメータ展開を使用する。

# mkcd: ディレクトリを作成してcdする
mkcd() {
  if [[ -z "$1" ]]; then
    echo "使い方: mkcd <dir>" >&2
    return 1
  fi
  mkdir -p "$1" && cd "$1"
}

ベストプラクティス(2026年)

  • 行う: ~/.zcompdumpをバイトコンパイルファイル(compdump.zwc)にコンパイルして、シェルの起動時間を高速化する。
  • 行う: setopt SHARE_HISTORYを設定して、すべてのアクティブなターミナルタブ間でコマンド履歴を同期する。
  • 行う: 肥大化した従来のプロンプトテーマではなく、Starshipまたは軽量なネイティブプロンプトを使用する。
  • 行う: zmodload zsh/zprofを~/.zshrcの先頭と末尾で使用して起動レイテンシをプロファイリングする。
  • 行わない: 不要なプラグインを多数含む、重く肥大化したフレームワーク設定(モノリシックなOh-My-Zsh設定)を使用しない。
  • 行わない: クラウド認証情報、APIトークン、シークレットを~/.zshrcに平文で保存しない。代わりにプライベートな.envファイルやシークレットボルトを使用する。
  • 行わない: インタラクティブなシェル起動時に、遅い外部コマンド(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].

関連スキル