refactor(shell): collapse managed tree back into stubs
Drop ~/.config/zsh/{env,interactive,login} modules. PATH and local.zsh
live in .zshenv; interactive UX is a single .zshrc again. Deploy only
installs the three stubs and removes obsolete trees/examples.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install managed easyzsh shell layout into a home directory.
|
||||
# Overwrites: ~/.zshenv ~/.zshrc ~/.zprofile ~/.config/zsh/{env,interactive,login}
|
||||
# Install easyzsh shell stubs into a home directory.
|
||||
# Overwrites: ~/.zshenv ~/.zshrc ~/.zprofile
|
||||
# Never overwrites: ~/.config/zsh/local.zsh ~/.config/zshrc/** ~/.local/bin/**
|
||||
#
|
||||
# Usage:
|
||||
@@ -56,17 +56,15 @@ file_has_content() {
|
||||
[[ -f "$1" ]] && grep -q '[^[:space:]]' "$1"
|
||||
}
|
||||
|
||||
echo "Deploying easyzsh managed shell layout into $TARGET_HOME"
|
||||
echo "Deploying easyzsh shell stubs into $TARGET_HOME"
|
||||
|
||||
mkdir -p \
|
||||
"${ZSH_CFG}/env" \
|
||||
"${ZSH_CFG}/interactive" \
|
||||
"${ZSH_CFG}/login" \
|
||||
"${ZSH_CFG}" \
|
||||
"${TARGET_HOME}/.config/zshrc" \
|
||||
"${TARGET_HOME}/.cache/zsh" \
|
||||
"${TARGET_HOME}/.local/bin"
|
||||
|
||||
# Migrate split local/* and legacy paths into ~/.config/zsh/local.zsh once.
|
||||
# Migrate legacy fragments into local.zsh once.
|
||||
if [[ ! -f "$LOCAL_ZSH" ]]; then
|
||||
tmp=$(mktemp)
|
||||
: >"$tmp"
|
||||
@@ -83,29 +81,17 @@ if [[ ! -f "$LOCAL_ZSH" ]]; then
|
||||
done
|
||||
fi
|
||||
if file_has_content "$tmp"; then
|
||||
# De-dup consecutive identical non-empty lines lightly by collapsing exact file repeats later if needed.
|
||||
cp "$tmp" "$LOCAL_ZSH"
|
||||
echo "Migrated machine-local fragments -> ~/.config/zsh/local.zsh"
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
fi
|
||||
|
||||
# After migration (or if local.zsh already exists), drop obsolete split files.
|
||||
if [[ -d "${ZSH_CFG}/local" ]]; then
|
||||
rm -f \
|
||||
"${ZSH_CFG}/local/env.local.zsh" \
|
||||
"${ZSH_CFG}/local/login.local.zsh" \
|
||||
"${ZSH_CFG}/local/interactive.local.zsh" \
|
||||
"${ZSH_CFG}/local/env.local.zsh.example" \
|
||||
"${ZSH_CFG}/local/login.local.zsh.example" \
|
||||
"${ZSH_CFG}/local/interactive.local.zsh.example"
|
||||
rmdir "${ZSH_CFG}/local" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Fold a pre-easyzsh ~/.zprofile into local.zsh. Skip if already an easyzsh stub.
|
||||
# Fold a pre-easyzsh ~/.zprofile into local.zsh. Skip easyzsh stub / empty files.
|
||||
if [[ "$MIGRATE_ZPROFILE" -eq 1 && -f "${TARGET_HOME}/.zprofile" ]]; then
|
||||
if grep -Fq 'easyzsh stub' "${TARGET_HOME}/.zprofile"; then
|
||||
echo "Skipping zprofile migration: already an easyzsh stub"
|
||||
if grep -Eq 'easyzsh|PATH lives in|Machine-local env' "${TARGET_HOME}/.zprofile" 2>/dev/null \
|
||||
|| grep -Fq 'Leave this file empty' "${TARGET_HOME}/.zprofile" 2>/dev/null; then
|
||||
echo "Skipping zprofile migration: already easyzsh-managed"
|
||||
elif [[ ! -f "$LOCAL_ZSH" ]]; then
|
||||
zprofile_extract=$(mktemp)
|
||||
awk '
|
||||
@@ -122,13 +108,6 @@ if [[ "$MIGRATE_ZPROFILE" -eq 1 && -f "${TARGET_HOME}/.zprofile" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Remove a broken local.zsh produced by an earlier stub-body migration.
|
||||
if [[ -f "$LOCAL_ZSH" ]] && grep -Fq 'local/login.local.zsh' "$LOCAL_ZSH" && ! grep -Eq 'cargo|OrbStack|MacPorts|Kiro|fnm' "$LOCAL_ZSH"; then
|
||||
backup_file "$LOCAL_ZSH"
|
||||
rm -f "$LOCAL_ZSH"
|
||||
echo "Removed broken stub residue from local.zsh"
|
||||
fi
|
||||
|
||||
backup_file "${TARGET_HOME}/.zshenv"
|
||||
backup_file "${TARGET_HOME}/.zshrc"
|
||||
backup_file "${TARGET_HOME}/.zprofile"
|
||||
@@ -137,19 +116,15 @@ install -m 644 "${ROOT}/.zshenv" "${TARGET_HOME}/.zshenv"
|
||||
install -m 644 "${ROOT}/.zshrc" "${TARGET_HOME}/.zshrc"
|
||||
install -m 644 "${ROOT}/.zprofile" "${TARGET_HOME}/.zprofile"
|
||||
|
||||
# Replace managed modules only (never touch local.zsh).
|
||||
rm -f "${ZSH_CFG}/env"/*.zsh
|
||||
rm -f "${ZSH_CFG}/interactive"/*.zsh
|
||||
rm -f "${ZSH_CFG}/login"/*.zsh
|
||||
install -m 644 "${ROOT}/config/env/"*.zsh "${ZSH_CFG}/env/"
|
||||
install -m 644 "${ROOT}/config/interactive/"*.zsh "${ZSH_CFG}/interactive/"
|
||||
if compgen -G "${ROOT}/config/login/"*.zsh > /dev/null; then
|
||||
install -m 644 "${ROOT}/config/login/"*.zsh "${ZSH_CFG}/login/"
|
||||
fi
|
||||
|
||||
if [[ -f "${ROOT}/local.zsh.example" ]]; then
|
||||
install -m 644 "${ROOT}/local.zsh.example" "${ZSH_CFG}/local.zsh.example"
|
||||
fi
|
||||
# Remove obsolete managed-tree layout and examples from earlier deploys.
|
||||
/bin/rm -rf \
|
||||
"${ZSH_CFG}/env" \
|
||||
"${ZSH_CFG}/interactive" \
|
||||
"${ZSH_CFG}/login" \
|
||||
"${ZSH_CFG}/local"
|
||||
/bin/rm -f \
|
||||
"${ZSH_CFG}/local.zsh.example" \
|
||||
"${TARGET_HOME}/.config/zshenv.local"
|
||||
|
||||
# Ensure intentional grok shim when the binary tree exists.
|
||||
if [[ -e "${TARGET_HOME}/.grok/bin/grok" ]]; then
|
||||
@@ -158,4 +133,4 @@ if [[ -e "${TARGET_HOME}/.grok/bin/grok" ]]; then
|
||||
fi
|
||||
|
||||
echo "Deploy complete."
|
||||
echo "Verify: env -i HOME=\"$TARGET_HOME\" PATH=/usr/bin:/bin zsh -c '. ~/.zshenv; command -v grok; echo PATH=\$PATH'"
|
||||
echo "Verify: env -i HOME=\"$TARGET_HOME\" PATH=/usr/bin:/bin zsh -c '. ~/.zshenv; command -v grok'"
|
||||
|
||||
Reference in New Issue
Block a user