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
+37 -29
View File
@@ -241,50 +241,58 @@ fi
ZSH="$HOME/.oh-my-zsh"
EASYZSH_RAW_BASE="${EASYZSH_RAW_BASE:-https://git.miomio.moe/mio/easyzsh/raw/branch/master}"
# Stage managed shell layout (stubs + ~/.config/zsh modules), then deploy.sh installs it.
# On download failure, leave existing ~/.zshrc and ~/.zshenv untouched.
easyzsh_stage=$(mktemp -d "$HOME/.easyzsh-stage.XXXXXX")
zshrc_download=$(mktemp "$HOME/.zshrc.download.XXXXXX")
zshenv_download=$(mktemp "$HOME/.zshenv.download.XXXXXX")
trap 'rm -f "$zshrc_download" "$zshenv_download"' EXIT
wget -q "https://git.miomio.moe/mio/easyzsh/raw/branch/master/.zshrc" -O "$zshrc_download"
wget -q "https://git.miomio.moe/mio/easyzsh/raw/branch/master/.zshenv" -O "$zshenv_download"
trap 'rm -rf "$easyzsh_stage"; rm -f "$zshrc_download" "$zshenv_download"' EXIT
# echo -e "The setup will be installed in '~/.config/ezsh'\n"
# echo -e "Place your personal zshrc config files under '~/.config/ezsh/zshrc/'\n"
# mkdir -p ~/.config/ezsh/zshrc # PLACE YOUR ZSHRC CONFIGURATIONS OVER THERE
download_easyzsh_file() {
local rel="$1"
local dest="$easyzsh_stage/$rel"
mkdir -p "$(dirname "$dest")"
if ! wget -q "${EASYZSH_RAW_BASE}/${rel}" -O "$dest"; then
echo "Failed to download ${rel} from ${EASYZSH_RAW_BASE}" >&2
exit 1
fi
}
# if [ -d ~/.quickzsh ]; then
# echo -e "\n PREVIOUS SETUP FOUND AT '~/.quickzsh'. PLEASE MANUALLY MOVE ANY FILES YOU'D LIKE TO '~/.config/ezsh' \n"
# fi
echo -e "Downloading easyzsh shell layout\n"
for rel in \
deploy.sh \
.zshenv \
.zshrc \
.zprofile \
config/env/00-path.zsh \
config/interactive/10-bootstrap.zsh \
config/interactive/20-post-omz.zsh \
local/env.local.zsh.example \
local/login.local.zsh.example \
local/interactive.local.zsh.example
do
download_easyzsh_file "$rel"
done
# Keep failure-detection temps in sync with legacy test expectations.
cp "$easyzsh_stage/.zshrc" "$zshrc_download"
cp "$easyzsh_stage/.zshenv" "$zshenv_download"
chmod +x "$easyzsh_stage/deploy.sh"
echo -e "Installing oh-my-zsh\n"
if [ -d "$ZSH" ]; then
echo -e "oh-my-zsh is already installed\n"
git -C "$ZSH" remote set-url origin https://github.com/ohmyzsh/ohmyzsh.git
# elif [ -d ~/.oh-my-zsh ]; then
# echo -e "oh-my-zsh in already installed at '~/.oh-my-zsh'. Moving it to '$ZSH'"
# export ZSH="$HOME/.config/ezsh/oh-my-zsh"
# mv ~/.oh-my-zsh $ZSH
# git -C $ZSH remote set-url origin https://github.com/ohmyzsh/ohmyzsh.git
else
git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git "$ZSH"
fi
if [ -e "$HOME/.zshrc" ] || [ -L "$HOME/.zshrc" ]; then
zshrc_backup=$(mktemp "$HOME/.zshrc.backup.$(date +"%Y%m%d-%H%M%S").XXXXXX")
cp -Pp "$HOME/.zshrc" "$zshrc_backup"
echo -e "Backed up the current .zshrc to $zshrc_backup\n"
fi
if [ -e "$HOME/.zshenv" ] || [ -L "$HOME/.zshenv" ]; then
zshenv_backup=$(mktemp "$HOME/.zshenv.backup.$(date +"%Y%m%d-%H%M%S").XXXXXX")
cp -Pp "$HOME/.zshenv" "$zshenv_backup"
echo -e "Backed up the current .zshenv to $zshenv_backup\n"
fi
mv "$zshrc_download" "$HOME/.zshrc"
mv "$zshenv_download" "$HOME/.zshenv"
# deploy.sh backs up existing stubs and never overwrites ~/.config/zsh/local/
bash "$easyzsh_stage/deploy.sh" --migrate-zprofile
trap - EXIT
# cp -f ezshrc.zsh ~/.config/ezsh/
# cp -f p10k.zsh ~/.config/ezsh/
rm -rf "$easyzsh_stage"
rm -f "$zshrc_download" "$zshenv_download"
mkdir -p ~/.cache/zsh/ # this will be used to store .zcompdump zsh completion cache files which normally clutter $HOME
mkdir -p ~/.fonts # Create .fonts if doesn't exist