refactor(shell): stop managing ~/.zprofile
Always-on and machine hooks already live in .zshenv / local.zsh. Drop the empty stub, remove it on deploy, and leave real .zprofile files to optional migration into local.zsh only.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
# Login shell hook. easyzsh keeps PATH and machine-local env in ~/.zshenv
|
||||
# (via ~/.config/zsh/local.zsh). Leave this file empty unless a tool insists
|
||||
# on writing login-only hooks here — prefer moving those into local.zsh.
|
||||
@@ -25,11 +25,12 @@ From a git checkout:
|
||||
| --- | --- | --- |
|
||||
| `~/.zshenv` | Always-on: Homebrew, `~/.local/bin`, source `local.zsh` | Overwritten |
|
||||
| `~/.zshrc` | Interactive: omz, plugins, aliases, fzf, zoxide | Overwritten |
|
||||
| `~/.zprofile` | Login placeholder (prefer `local.zsh` for machine hooks) | Overwritten |
|
||||
| `~/.config/zsh/local.zsh` | Machine-local overrides (every zsh, including agents) | **Never overwritten** |
|
||||
| `~/.config/zshrc/*.zsh` | Personal/tool overlays before oh-my-zsh | Left alone |
|
||||
| `~/.local/bin/` | User tools + shims (e.g. `grok` → `~/.grok/bin/grok`) | Left alone |
|
||||
|
||||
easyzsh does **not** manage `~/.zprofile`. Put machine/login hooks in `local.zsh`.
|
||||
|
||||
Do **not** put `~/.grok/bin` on PATH wholesale.
|
||||
|
||||
```bash
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install easyzsh shell stubs into a home directory.
|
||||
# Overwrites: ~/.zshenv ~/.zshrc ~/.zprofile
|
||||
# Overwrites: ~/.zshenv ~/.zshrc
|
||||
# Never overwrites: ~/.config/zsh/local.zsh ~/.config/zshrc/** ~/.local/bin/**
|
||||
# Does not manage ~/.zprofile (machine/login hooks belong in local.zsh).
|
||||
#
|
||||
# Usage:
|
||||
# ./deploy.sh
|
||||
# ./deploy.sh --home /path/to/home
|
||||
# ./deploy.sh --migrate-zprofile # fold pre-easyzsh ~/.zprofile into local.zsh
|
||||
# ./deploy.sh --migrate-zprofile # fold real ~/.zprofile into local.zsh, then remove stub
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -42,6 +43,7 @@ fi
|
||||
|
||||
ZSH_CFG="${TARGET_HOME}/.config/zsh"
|
||||
LOCAL_ZSH="${ZSH_CFG}/local.zsh"
|
||||
ZPROFILE="${TARGET_HOME}/.zprofile"
|
||||
ts=$(date +%Y%m%d-%H%M%S)
|
||||
|
||||
backup_file() {
|
||||
@@ -56,6 +58,16 @@ file_has_content() {
|
||||
[[ -f "$1" ]] && grep -q '[^[:space:]]' "$1"
|
||||
}
|
||||
|
||||
is_easyzsh_zprofile_stub() {
|
||||
local f="$1"
|
||||
[[ -f "$f" ]] || return 1
|
||||
# Comment-only placeholder from earlier easyzsh deploys.
|
||||
if grep -Eqv '^[[:space:]]*(#|$)' "$f"; then
|
||||
return 1
|
||||
fi
|
||||
grep -Eq 'easyzsh|PATH lives in|Leave this file empty|prefer.*local\.zsh' "$f"
|
||||
}
|
||||
|
||||
echo "Deploying easyzsh shell stubs into $TARGET_HOME"
|
||||
|
||||
mkdir -p \
|
||||
@@ -87,11 +99,11 @@ if [[ ! -f "$LOCAL_ZSH" ]]; then
|
||||
rm -f "$tmp"
|
||||
fi
|
||||
|
||||
# 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 -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"
|
||||
# Optional: fold a real (non-stub) ~/.zprofile into local.zsh.
|
||||
if [[ "$MIGRATE_ZPROFILE" -eq 1 && -f "$ZPROFILE" ]]; then
|
||||
if is_easyzsh_zprofile_stub "$ZPROFILE"; then
|
||||
echo "Removing easyzsh ~/.zprofile stub (hooks live in local.zsh / .zshenv)"
|
||||
rm -f "$ZPROFILE"
|
||||
elif [[ ! -f "$LOCAL_ZSH" ]]; then
|
||||
zprofile_extract=$(mktemp)
|
||||
awk '
|
||||
@@ -99,22 +111,30 @@ if [[ "$MIGRATE_ZPROFILE" -eq 1 && -f "${TARGET_HOME}/.zprofile" ]]; then
|
||||
skip_pipx && /local\/bin/ { skip_pipx=0; next }
|
||||
skip_pipx { next }
|
||||
{ print }
|
||||
' "${TARGET_HOME}/.zprofile" >"$zprofile_extract"
|
||||
' "$ZPROFILE" >"$zprofile_extract"
|
||||
if file_has_content "$zprofile_extract"; then
|
||||
cp "$zprofile_extract" "$LOCAL_ZSH"
|
||||
echo "Migrated ~/.zprofile body -> ~/.config/zsh/local.zsh"
|
||||
rm -f "$ZPROFILE"
|
||||
echo "Removed ~/.zprofile after migration"
|
||||
fi
|
||||
rm -f "$zprofile_extract"
|
||||
elif is_easyzsh_zprofile_stub "$ZPROFILE"; then
|
||||
rm -f "$ZPROFILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Always drop the comment-only easyzsh stub if present (even without --migrate).
|
||||
if is_easyzsh_zprofile_stub "$ZPROFILE"; then
|
||||
rm -f "$ZPROFILE"
|
||||
echo "Removed empty easyzsh ~/.zprofile stub"
|
||||
fi
|
||||
|
||||
backup_file "${TARGET_HOME}/.zshenv"
|
||||
backup_file "${TARGET_HOME}/.zshrc"
|
||||
backup_file "${TARGET_HOME}/.zprofile"
|
||||
|
||||
install -m 644 "${ROOT}/.zshenv" "${TARGET_HOME}/.zshenv"
|
||||
install -m 644 "${ROOT}/.zshrc" "${TARGET_HOME}/.zshrc"
|
||||
install -m 644 "${ROOT}/.zprofile" "${TARGET_HOME}/.zprofile"
|
||||
|
||||
# Remove obsolete managed-tree layout and examples from earlier deploys.
|
||||
/bin/rm -rf \
|
||||
|
||||
+1
-2
@@ -264,8 +264,7 @@ echo -e "Downloading easyzsh shell stubs\n"
|
||||
for rel in \
|
||||
deploy.sh \
|
||||
.zshenv \
|
||||
.zshrc \
|
||||
.zprofile
|
||||
.zshrc
|
||||
do
|
||||
download_easyzsh_file "$rel"
|
||||
done
|
||||
|
||||
+2
-1
@@ -81,10 +81,11 @@ for script in "$ROOT"/*.sh; do
|
||||
bash -n "$script"
|
||||
done
|
||||
|
||||
for config in "$ROOT/.zshenv" "$ROOT/.zshrc" "$ROOT/.zprofile" "$ROOT"/zshrc/*.zsh; do
|
||||
for config in "$ROOT/.zshenv" "$ROOT/.zshrc" "$ROOT"/zshrc/*.zsh; do
|
||||
[[ -f "$config" ]] || continue
|
||||
zsh -n "$config"
|
||||
done
|
||||
[[ ! -e "$ROOT/.zprofile" ]] || fail "easyzsh should not ship a managed .zprofile"
|
||||
|
||||
grep -q 'NVM_VERSION="v0.40.4"' "$ROOT/install_nvm.sh" || fail "nvm version is stale"
|
||||
grep -q 'apt-get install -y unzip' "$ROOT/install_fnm.sh" || fail "Ubuntu unzip installation is missing"
|
||||
|
||||
Reference in New Issue
Block a user