zinit 插件配置 2025
mac电脑,x86架构
zshrc配置
# ===================================================================
# ⚡ Powerlevel10k 即时提示(必须靠近顶部,且仅出现一次)
# ===================================================================
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# ===================================================================
# 🔌 Zinit 插件管理器安装与加载
# ===================================================================
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33}▓%F{34}▓%F{35}▓%F{37} Installing Zinit Plugin Manager...%f"
command mkdir -p "$HOME/.local/share/zinit"
command chmod g-rwX "$HOME/.local/share/zinit"
git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" --depth=1 && \
print -P "%F{34}Installation successful!%f" || \
print -P "%F{196}The clone has failed.%f"
fi
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
# ===================================================================
# 🔧 加载 Zinit 核心 Annex(必须)
# ===================================================================
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust
# ===================================================================
# 🎨 Powerlevel10k 主题
# ===================================================================
zinit ice depth=1
zinit light romkatv/powerlevel10k
# ===================================================================
# ⚙️ Zsh 核心功能(延迟加载)
# ===================================================================
zinit wait"1" lucid for \
OMZL::clipboard.zsh \
OMZL::history.zsh \
OMZL::key-bindings.zsh \
OMZL::completion.zsh
# ===================================================================
# 🔍 补全与提示系统
# ===================================================================
# 语法高亮 + 自动建议 + 历史搜索
zinit for \
wait"0" lucid light-mode \
zdharma-continuum/fast-syntax-highlighting \
zsh-users/zsh-autosuggestions \
zdharma-continuum/history-search-multi-word
# fzf-tab:可视化模糊补全
zinit ice lucid wait'0'
zinit light Aloxaf/fzf-tab
# z.lua:智能目录跳转
zinit ice lucid wait'0'
zinit light skywind3000/z.lua
# ===================================================================
# 🧰 常用 CLI 工具(修复语法错误)
# ===================================================================
# 使用正确的 Zinit 语法:as"command" 而不是 ascommand
zinit ice as"command" from"gh-r" mv"fd* -> fd" pick"fd/fd"
zinit light sharkdp/fd
zinit ice as"command" from"gh-r" mv"bat* -> bat" pick"bat/bat"
zinit light sharkdp/bat
# zinit ice as"command" from"gh-r" mv"eza* -> eza" pick"eza/eza"
# zinit light eza-community/eza
zinit ice as"command" from"gh-r" mv"ripgrep* -> rg" pick"rg/rg"
zinit light BurntSushi/ripgrep
zinit ice as"command" from"gh-r" pick"sd"
zinit light chmln/sd
zinit ice as"command" from"gh-r" mv"delta* -> delta" pick"delta/delta"
zinit light dandavison/delta
zinit ice as"command" from"gh-r" pick"dog"
zinit light ogham/dog
zinit ice as"command" from"gh-r" mv"hyperfine* -> hyperfine" pick"hyperfine/hyperfine"
zinit light sharkdp/hyperfine
zinit ice as"program" from"gh-r" pick"fzf"
zinit light junegunn/fzf
# pet - macOS 版本检测
if [[ "$OSTYPE" == darwin* ]]; then
zinit ice as"command" from"gh-r" pick"*darwin*"
else
zinit ice as"command" from"gh-r" pick"*linux*"
fi
# 使用 knqyf263/pet(原始版本)
zinit ice as"command" from"gh-r" pick"pet-*darwin*"
zinit light knqyf263/pet
# httpstat
zinit ice as"program" pick"httpstat.sh" atpull'!git reset --hard'
zinit light b4b4r07/httpstat
# ===================================================================
# 🎯 补全与交互优化
# ===================================================================
# 启用带选择菜单的补全
zstyle ':completion:*' menu select
# macOS 兼容的 fzf-tab 预览
if [[ "$OSTYPE" == darwin* ]]; then
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
zstyle ':fzf-tab:complete:git-checkout:*' fzf-preview 'git log --oneline --graph --color=always $word | head -20'
zstyle ':fzf-tab:complete:kill:*' fzf-preview 'ps -p $realpath[#,-1] -o pid,%cpu,%mem,comm -c' --height=20
else
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
zstyle ':fzf-tab:complete:git-checkout:*' fzf-preview 'git log --oneline --graph --color=always $word | head -20'
zstyle ':fzf-tab:complete:kill:*' fzf-preview 'ps --pid=$realpath[#,-1] -o pid,%cpu,%mem,cmd --width=${COLUMNS} --color=always' --height=20
fi
# ===================================================================
# 🔧 初始化补全系统
# ===================================================================
autoload -Uz compinit
if [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]]; then
compinit
else
compinit -C
fi
# ===================================================================
# 🚀 环境变量、别名、外部配置加载
# ===================================================================
[ -f ~/.profile ] && source ~/.profile
config_files=(
~/.config/.env.sh
~/.config/.zsh.sh
~/.config/.alias.sh
~/.config/.fun.sh
~/.config/.proxy.sh
)
for file in "${config_files[@]}"; do
[[ -f $file ]] && source "$file"
done
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# ===================================================================
# 🔧 快捷键设置
# ===================================================================
bindkey ',' autosuggest-accept
# ===================================================================
# 🧩 可选插件(按需启用)
# ===================================================================
# zinit light wfxr/forgit
# zinit light zdharma-continuum/git-tools
# zinit auto-update --period=7
# ===================================================================
# 🔧 macOS 特定设置
# ===================================================================
if [[ "$OSTYPE" == darwin* ]]; then
export LSCOLORS="ExFxBxDxCxegedabagacad"
if command -v brew >/dev/null 2>&1; then
export PATH="/usr/local/bin:$PATH"
fi
fi
相关别名配置
# =============================================================================
# 📂 eza - 现代化 ls 替代工具
# =============================================================================
# 💡 eza 是 exa 的接续项目,功能更丰富,支持图标、Git 状态、树状结构等
# 📦 安装方式:brew install eza
# 🔤 字体要求:建议使用 Nerd Fonts(如 JetBrainsMono Nerd Font)以显示图标
# 📁 用途:替代传统 ls 命令,提供更美观、更实用的文件列表
# =============================================================================
# 检查 eza 是否已安装,避免别名报错
if ! command -v eza >/dev/null 2>&1; then
echo "⚠️ eza 未安装,建议执行:brew install eza"
echo "💡 如需图标支持,请安装 Nerd Fonts 字体"
return 0
fi
# =============================================================================
# 🚀 基础别名(日常最常用)
# =============================================================================
# 使用 eza 替代 ls
# --icons 显示文件类型图标(需 Nerd Fonts)
# --group-directories-first 目录排在文件前面
# --color=always 始终启用颜色
# --time-style=long-iso 时间格式为 ISO 标准(YYYY-MM-DD HH:MM)
alias ls='eza --icons --group-directories-first --color=always --time-style=long-iso'
# 长格式列表(类似 ls -l)
# -l 长格式:权限、大小、时间、名称
# -h 人类可读大小(K, M, G)
alias ll='ls -lh'
# 显示所有文件(包括隐藏文件 . 和 ..)
# -a 显示所有条目(含 . 和 ..)
alias la='ll -a'
# 显示所有文件 + Git 状态(非常实用!)
# --git 显示 Git 状态(修改、新增、删除等)
# --git-ignore 显示 .gitignore 忽略的文件(灰色)
alias lg='la --git --git-ignore'
# =============================================================================
# 🌲 树状结构浏览(替代 tree 命令)
# =============================================================================
# 简单树状结构,最多显示 2 层
# --tree 启用树状显示
# --level=2 最多显示 2 层子目录
alias tree='eza --icons --tree --level=2 --color=always'
# 深度树状结构,最多 4 层
alias tree4='eza --icons --tree --level=4 --color=always'
# 智能树状结构:忽略常见大目录(提升性能)
# -I "pattern" 忽略匹配的文件/目录(支持通配符)
# 常见忽略项:
# node_modules/ 前端项目依赖
# .git/ Git 元数据
# dist/ build/ 构建输出
# __pycache__/ Python 缓存
# .DS_Store macOS 隐藏文件
alias lstr='eza --icons --tree --level=3 -I "node_modules|.git|dist|build|__pycache__|.DS_Store" --color=always'
# =============================================================================
# 🕒 排序相关
# =============================================================================
# 按修改时间排序(最新在前)
# -s modified 按修改时间排序
alias llt='ll -s modified'
# 按文件大小排序(从大到小)
# -s size 按大小排序
alias lls='ll -s size'
# =============================================================================
# 🔍 过滤与查找
# =============================================================================
# 只显示目录(末尾带 /)
# -d */ 只匹配以 / 结尾的条目(即目录)
alias lsd='ls -d */'
# 只显示文件(不包括目录)
# -F 为目录添加 /,可执行文件添加 *
# grep -v / 过滤掉目录
alias lsf='ls -F | grep -v /'
# =============================================================================
# 🔎 高级组合命令(可选)
# =============================================================================
# 在 fzf 中预览目录树(交互式)
# --height=40% fzf 占据 40% 高度
# --border 添加边框
# --ansi 支持颜色输出
alias ftree='eza --icons --tree --level=3 -I "node_modules|.git" | fzf --height=40% --border --ansi'
# 查看最近修改的 20 个文件
# --sort=modified 按修改时间排序
# head -20 取前 20 行
alias recent='eza -lah --sort=modified | head -20'
# 查看最大的 10 个文件
# tail -15 先取最后 15 个(避免 . .. 等)
# head -11 再取前 11 个(排除总计行)
alias bigfiles='eza -lah --sort=size | tail -15 | head -11'
# =============================================================================
# 🧩 可选:兼容性别名(如果你习惯传统命令)
# =============================================================================
# 如果你仍想用 ls 但不想带图标
# alias l='ls --no-icons'
# 如果你希望 tree 默认更深
# alias tree='eza --icons --tree --level=5 -I "node_modules|.git"'
# =============================================================================
# ✅ 使用建议
# =============================================================================
# 1. 将此文件保存为 ~/.config/.alias.sh
# 2. 确保 ~/.zshrc 中有:[[ -f ~/.config/.alias.sh ]] && source ~/.config/.alias.sh
# 3. 安装 eza:brew install eza
# 4. 安装 Nerd Fonts 字体(推荐 JetBrainsMono)
# 5. 在终端设置中切换字体
# 6. 重启终端或执行:source ~/.zshrc
# =============================================================================
# echo "✅ eza 别名已加载(共 15+ 个命令)"
# fzf 主动搜索
alias ff='fd --type f | fzf --height=40% --border --preview "bat --color=always --line-range :50 {}"'
alias gba='git branch -a | fzf --preview "git log --oneline {} --color=always" | sed "s/.* //" | xargs git checkout'
rgff() {
local query
query=$(rg --files 2>/dev/null | fzf --height=50% --border --prompt="🔍 Search for: " \
--preview "echo {}" \
--bind "change:reload:rg --color=always {q} ./{} || true" \
--preview-window=down:50%:wrap)
[[ -n "$query" ]] && print -S "$query" && echo "$query"
}
# 自定义函数
j() {
local dir
dir=$(fd --type d 2>/dev/null | fzf --height=40% --border --preview 'eza -lh --icons {}')
[[ -n "$dir" ]] && cd "$dir"
}

浙公网安备 33010602011771号