Files
archlinux-config/home/.zshrc
T
imbytecat 77d51c65b3 feat(zsh): 现代化 zshrc 配置并删除冗余 vim
zshrc 配置更新:
- 新增 EDITOR/VISUAL/MANPAGER/PAGER 环境变量,让 git commit、
  visudo、man 等工具默认使用 nvim 与 bat
- zoxide init --cmd cd 直接接管 cd,删除手动 alias cd=z/cdi=zi
- 新增 yazi yy wrapper:退出时自动 cd 到最后浏览的目录
- FZF 默认配置:fd 联动 + 现代 UI(高度/边框/预览窗口)
- compinit 缓存优化:每天重建一次 zcompdump,平时复用
- eza alias 公共参数提取到 _EZA_BASE,所有列表都带 --git
- 新增 Ctrl+Space 接受 zsh-autosuggestions 建议

base.py 同步:
- 删除冗余 vim:neovim 已装且 EDITOR=nvim 已设置,
  visudo 等工具会通过 $EDITOR fallback 到 nvim
2026-04-08 13:21:59 +08:00

95 lines
2.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ── PATH ──
export PATH="$HOME/go/bin:$HOME/.bun/bin:$PATH"
# ── 默认编辑器与分页器 ──
export EDITOR=nvim
export VISUAL=nvim
export PAGER=less
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
# ── Shell 选项 ──
setopt AUTO_CD # 输目录名直接 cd
setopt INTERACTIVE_COMMENTS # 允许交互式 # 注释
setopt NO_BEEP # 关蜂鸣
# ── 补全系统(必须在 fzf-tab 之前)──
# 每天重建一次 zcompdump,其余启动直接复用,节省启动时间
autoload -Uz compinit
if [[ -n ~/.zcompdump(#qN.mh+24) ]]; then
compinit
else
compinit -C
fi
# ── 外部插件 ──
source /usr/share/zsh/plugins/fzf-tab-git/fzf-tab.plugin.zsh
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh # 必须最后
# ── 双击 ESC 自动加 sudo ──
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
[[ $BUFFER != sudo\ * ]] && BUFFER="sudo $BUFFER"
zle end-of-line
}
zle -N sudo-command-line
bindkey '\e\e' sudo-command-line
# ── Ctrl+Space 接受自动建议 ──
bindkey '^ ' autosuggest-accept
# ── FZF 默认行为(fd 联动 + 现代 UI)──
export FZF_DEFAULT_OPTS='--height=50% --layout=reverse --border --preview-window=right:60%'
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
# ── 工具初始化(顺序重要)──
eval "$(starship init zsh)"
eval "$(zoxide init --cmd cd zsh)" # cd 直接被 zoxide 接管,cdi 自动可用
eval "$(mise activate zsh)"
eval "$(direnv hook zsh)"
eval "$(fzf --zsh)" # Ctrl+T 搜文件, Alt+C 搜目录
eval "$(atuin init zsh)" # 必须在 fzf 之后,接管 Ctrl+R
# ── 别名 ──
# 导航
alias ..="cd .."
alias ...="cd ../.."
# 文件列表(公共参数提取,DRY
_EZA_BASE=(--icons --group-directories-first --git)
alias ls="eza ${_EZA_BASE}"
alias ll="eza -la ${_EZA_BASE}"
alias la="eza -a ${_EZA_BASE}"
alias lt="eza --tree --level=2 ${_EZA_BASE}"
# 工具
alias cat="bat --paging=never"
alias rm="gomi"
alias lg="lazygit"
alias vi="nvim"
alias x="ouch decompress" # 万能解压(zip/tar/gz/bz2/xz/zst/7z/rar
# 网络
alias http="xh"
# ── yazi wrapper:退出时自动 cd 到最后目录 ──
function yy() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
if cwd="$(command cat -- "$tmp")" && [[ -n "$cwd" && "$cwd" != "$PWD" ]]; then
builtin cd -- "$cwd"
fi
command rm -f -- "$tmp"
}
# ── WSL 剪贴板 ──
if [[ -n "$WSL_DISTRO_NAME" ]]; then
alias pbcopy="clip.exe"
alias pbpaste="powershell.exe -noprofile -c Get-Clipboard"
fi
# ── Local ──
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local