refactor(shell): thin stubs with managed ~/.config/zsh tree

Split always-on PATH/env, login hooks, and interactive UX into a
managed tree under ~/.config/zsh, with never-overwrite local/ hooks.
Agents and interactive shells share one PATH owner; deploy.sh applies
the layout safely across machines.
This commit is contained in:
Jeffrey
2026-08-06 14:36:08 +08:00
parent ed5365859c
commit f8dcc29a2f
14 changed files with 546 additions and 391 deletions
+24
View File
@@ -0,0 +1,24 @@
# Sole managed PATH builder for every zsh (including non-interactive agents).
# Do not re-append user tool paths in .zprofile or .zshrc.
easyzsh_path_prepend() {
local dir="$1"
[[ -n "$dir" && -d "$dir" ]] || return 0
case ":${PATH}:" in
*":${dir}:"*) ;;
*) PATH="${dir}:${PATH}" ;;
esac
}
# Homebrew first so its shellenv can set prefix vars; we re-assert ~/.local/bin after.
if [[ -x /opt/homebrew/bin/brew ]]; then
eval "$(cd /tmp && /opt/homebrew/bin/brew shellenv)"
elif [[ -x /usr/local/bin/brew ]]; then
eval "$(cd /tmp && /usr/local/bin/brew shellenv)"
fi
# User-local binaries (pipx, uv tools, intentional shims such as grok).
# Never put vendor trees like ~/.grok/bin on PATH wholesale (generic names shadow tools).
easyzsh_path_prepend "${HOME}/.local/bin"
export PATH
+120
View File
@@ -0,0 +1,120 @@
# Interactive bootstrap: omz, plugins, personal overlays, completions.
# PATH is owned by env/00-path.zsh; do not rebuild it here.
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
# 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
export TERM="xterm-256color"
# Skip oh-my-zsh's completion security audit (compaudit). The completion dirs are
# machine-owned and not group/world-writable, so the per-startup audit only costs time.
export ZSH_DISABLE_COMPFIX=true
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Agent/AI terminals (Cursor's agent sets CURSOR_AGENT) get a light, fast theme;
# interactive shells use powerlevel10k.
if [[ -n "$CURSOR_AGENT" ]]; then
ZSH_THEME="robbyrussell"
else
ZSH_THEME="powerlevel10k/powerlevel10k"
fi
# How often to auto-update (days). Replaces the older UPDATE_ZSH_DAYS variable.
zstyle ':omz:update' frequency 30
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Add wisely, as too many plugins slow down shell startup.
plugins=(
# zsh-completions INSTALL METHOD CHANGED https://github.com/zsh-users/zsh-completions/issues/603
zsh-autosuggestions
zsh-syntax-highlighting
history-substring-search
systemd
k
extract
sudo
fzf-tab
poetry
# web-search
# httpie
# git
# python
# docker
# lol
# pip
# pyenv
# redis-cli
# screen
# zsh-wakatime # enable if you use wakatime with 'https://github.com/wbingli/zsh-wakatime'
)
# Plugins can be added in ~/.config/zshrc/*.zsh like:
# plugins+=(zsh-nvm)
# Remove plugins from the default list with:
# plugins=(${plugins:#pluginname})
fpath+=$ZSH/custom/plugins/zsh-completions/src
# Setup Homebrew completions for macOS
if [[ "$OSTYPE" == "darwin"* ]] && command -v brew &> /dev/null; then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
fi
mkdir -p ~/.cache/zsh
autoload -U compinit && compinit -C -d ~/.cache/zsh/.zcompdump
SAVEHIST=50000
# CUSTOM FUNCTIONS
# cheat sheets (github.com/chubin/cheat.sh)
cheat() {
if [ "$2" ]; then
curl "https://cheat.sh/$1/$2+$3+$4+$5+$6+$7+$8+$9+$10"
else
curl "https://cheat.sh/$1"
fi
}
speedtest() {
setopt localoptions pipefail
curl -fsSL https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -
}
dadjoke() {
curl https://icanhazdadjoke.com
}
# Strip macOS junk from a zip (requires `zip`). Usage: cleanzip archive.zip
cleanzip() {
zip -d "$@" __MACOSX/\* \*/.DS_Store
}
# Find geo info from IP
ipgeo() {
if [ "$1" ]; then
curl "https://api.db-ip.com/v2/free/$1"
else
curl "https://api.db-ip.com/v2/free/$(myip)"
fi
}
# Personal / tool overlays under ~/.config/zshrc/ (before oh-my-zsh so plugins apply).
# Managed interactive code lives in ~/.config/zsh/interactive/; do not put machine
# secrets here if they need to survive reinstall of managed files.
ZSH_CONFIGS_DIR="$HOME/.config/zshrc"
for file in "$ZSH_CONFIGS_DIR"/*(DN); do
if [ -f "$file" ]; then
source "$file"
fi
done
# Source oh-my-zsh after overlays so plugins+=(…) from ~/.config/zshrc take effect.
source "$ZSH/oh-my-zsh.sh"
+70
View File
@@ -0,0 +1,70 @@
# Runs after oh-my-zsh so these aliases win over omz defaults.
alias myip="wget -qO- https://wtfismyip.com/text"
alias l="eza --hyperlink -lA --sort=modified --reverse --classify"
alias e="exit"
alias ip="ip --color=auto"
## EZA - the better ls command
alias a='eza -la --git --colour-scale all -g --smart-group --icons always --hyperlink'
alias aa='eza -la --git --colour-scale all -g --smart-group --icons always -s modified -r --hyperlink'
# rm moves files to Trash while tolerating standard rm flags: -f suppresses
# missing-file errors; other flags are no-ops (trash backends are already
# recursive). Files whose names start with "-" still need /bin/rm.
# Shell snapshots (Claude Code etc.) restore functions but not global arrays,
# so rm() re-resolves the backend when _TRASH_CMD is empty at call time.
_resolve_trash_cmd() {
if [[ "$OSTYPE" == darwin* && -x /usr/bin/trash ]]; then
typeset -ga _TRASH_CMD=(/usr/bin/trash)
elif [[ "$OSTYPE" == darwin* ]] && command -v rmtrash &> /dev/null; then
typeset -ga _TRASH_CMD=(rmtrash)
elif [[ "$OSTYPE" != darwin* ]] && command -v gio &> /dev/null; then
typeset -ga _TRASH_CMD=(gio trash)
elif [[ "$OSTYPE" != darwin* ]] && command -v trash-put &> /dev/null; then
typeset -ga _TRASH_CMD=(trash-put)
fi
}
_resolve_trash_cmd
if (( ${#_TRASH_CMD[@]} )); then
rm() {
(( ${#_TRASH_CMD[@]} )) || _resolve_trash_cmd
(( ${#_TRASH_CMD[@]} )) || { command rm "$@"; return }
local force=0 arg
local -a paths existing
for arg in "$@"; do
case "$arg" in
--) ;;
-*f*) force=1 ;;
-*) ;;
*) paths+=("$arg") ;;
esac
done
(( ${#paths[@]} )) || return 0
if (( force )); then
for arg in "${paths[@]}"; do
[[ -e "$arg" || -L "$arg" ]] && existing+=("$arg")
done
(( ${#existing[@]} )) || return 0
"${_TRASH_CMD[@]}" "${existing[@]}"
else
"${_TRASH_CMD[@]}" "${paths[@]}"
fi
}
fi
# Now source fzf.zsh , otherwise Ctrl+r is overwritten by ohmyzsh
if [[ -x "$HOME/.fzf/bin/fzf" ]] && ! fzf --zsh >/dev/null 2>&1; then
path=("$HOME/.fzf/bin" ${path:#$HOME/.fzf/bin})
fi
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_OPS="--extended"
# Initialize zoxide (smarter cd command)
command -v zoxide &> /dev/null && eval "$(zoxide init zsh)"
# Short jump alias; expands at use time after zoxide defines `z`.
alias j="z"
# k plugin ships a `k` function; only alias when it actually loaded.
if (( $+functions[k] )); then
alias k="k -h"
fi
View File