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 |
|
| `~/.zshenv` | Always-on: Homebrew, `~/.local/bin`, source `local.zsh` | Overwritten |
|
||||||
| `~/.zshrc` | Interactive: omz, plugins, aliases, fzf, zoxide | 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/zsh/local.zsh` | Machine-local overrides (every zsh, including agents) | **Never overwritten** |
|
||||||
| `~/.config/zshrc/*.zsh` | Personal/tool overlays before oh-my-zsh | Left alone |
|
| `~/.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 |
|
| `~/.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.
|
Do **not** put `~/.grok/bin` on PATH wholesale.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Install easyzsh shell stubs into a home directory.
|
# 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/**
|
# Never overwrites: ~/.config/zsh/local.zsh ~/.config/zshrc/** ~/.local/bin/**
|
||||||
|
# Does not manage ~/.zprofile (machine/login hooks belong in local.zsh).
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./deploy.sh
|
# ./deploy.sh
|
||||||
# ./deploy.sh --home /path/to/home
|
# ./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
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ fi
|
|||||||
|
|
||||||
ZSH_CFG="${TARGET_HOME}/.config/zsh"
|
ZSH_CFG="${TARGET_HOME}/.config/zsh"
|
||||||
LOCAL_ZSH="${ZSH_CFG}/local.zsh"
|
LOCAL_ZSH="${ZSH_CFG}/local.zsh"
|
||||||
|
ZPROFILE="${TARGET_HOME}/.zprofile"
|
||||||
ts=$(date +%Y%m%d-%H%M%S)
|
ts=$(date +%Y%m%d-%H%M%S)
|
||||||
|
|
||||||
backup_file() {
|
backup_file() {
|
||||||
@@ -56,6 +58,16 @@ file_has_content() {
|
|||||||
[[ -f "$1" ]] && grep -q '[^[:space:]]' "$1"
|
[[ -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"
|
echo "Deploying easyzsh shell stubs into $TARGET_HOME"
|
||||||
|
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
@@ -87,11 +99,11 @@ if [[ ! -f "$LOCAL_ZSH" ]]; then
|
|||||||
rm -f "$tmp"
|
rm -f "$tmp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fold a pre-easyzsh ~/.zprofile into local.zsh. Skip easyzsh stub / empty files.
|
# Optional: fold a real (non-stub) ~/.zprofile into local.zsh.
|
||||||
if [[ "$MIGRATE_ZPROFILE" -eq 1 && -f "${TARGET_HOME}/.zprofile" ]]; then
|
if [[ "$MIGRATE_ZPROFILE" -eq 1 && -f "$ZPROFILE" ]]; then
|
||||||
if grep -Eq 'easyzsh|PATH lives in|Machine-local env' "${TARGET_HOME}/.zprofile" 2>/dev/null \
|
if is_easyzsh_zprofile_stub "$ZPROFILE"; then
|
||||||
|| grep -Fq 'Leave this file empty' "${TARGET_HOME}/.zprofile" 2>/dev/null; then
|
echo "Removing easyzsh ~/.zprofile stub (hooks live in local.zsh / .zshenv)"
|
||||||
echo "Skipping zprofile migration: already easyzsh-managed"
|
rm -f "$ZPROFILE"
|
||||||
elif [[ ! -f "$LOCAL_ZSH" ]]; then
|
elif [[ ! -f "$LOCAL_ZSH" ]]; then
|
||||||
zprofile_extract=$(mktemp)
|
zprofile_extract=$(mktemp)
|
||||||
awk '
|
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 && /local\/bin/ { skip_pipx=0; next }
|
||||||
skip_pipx { next }
|
skip_pipx { next }
|
||||||
{ print }
|
{ print }
|
||||||
' "${TARGET_HOME}/.zprofile" >"$zprofile_extract"
|
' "$ZPROFILE" >"$zprofile_extract"
|
||||||
if file_has_content "$zprofile_extract"; then
|
if file_has_content "$zprofile_extract"; then
|
||||||
cp "$zprofile_extract" "$LOCAL_ZSH"
|
cp "$zprofile_extract" "$LOCAL_ZSH"
|
||||||
echo "Migrated ~/.zprofile body -> ~/.config/zsh/local.zsh"
|
echo "Migrated ~/.zprofile body -> ~/.config/zsh/local.zsh"
|
||||||
|
rm -f "$ZPROFILE"
|
||||||
|
echo "Removed ~/.zprofile after migration"
|
||||||
fi
|
fi
|
||||||
rm -f "$zprofile_extract"
|
rm -f "$zprofile_extract"
|
||||||
|
elif is_easyzsh_zprofile_stub "$ZPROFILE"; then
|
||||||
|
rm -f "$ZPROFILE"
|
||||||
fi
|
fi
|
||||||
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}/.zshenv"
|
||||||
backup_file "${TARGET_HOME}/.zshrc"
|
backup_file "${TARGET_HOME}/.zshrc"
|
||||||
backup_file "${TARGET_HOME}/.zprofile"
|
|
||||||
|
|
||||||
install -m 644 "${ROOT}/.zshenv" "${TARGET_HOME}/.zshenv"
|
install -m 644 "${ROOT}/.zshenv" "${TARGET_HOME}/.zshenv"
|
||||||
install -m 644 "${ROOT}/.zshrc" "${TARGET_HOME}/.zshrc"
|
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.
|
# Remove obsolete managed-tree layout and examples from earlier deploys.
|
||||||
/bin/rm -rf \
|
/bin/rm -rf \
|
||||||
|
|||||||
+1
-2
@@ -264,8 +264,7 @@ echo -e "Downloading easyzsh shell stubs\n"
|
|||||||
for rel in \
|
for rel in \
|
||||||
deploy.sh \
|
deploy.sh \
|
||||||
.zshenv \
|
.zshenv \
|
||||||
.zshrc \
|
.zshrc
|
||||||
.zprofile
|
|
||||||
do
|
do
|
||||||
download_easyzsh_file "$rel"
|
download_easyzsh_file "$rel"
|
||||||
done
|
done
|
||||||
|
|||||||
+2
-1
@@ -81,10 +81,11 @@ for script in "$ROOT"/*.sh; do
|
|||||||
bash -n "$script"
|
bash -n "$script"
|
||||||
done
|
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
|
[[ -f "$config" ]] || continue
|
||||||
zsh -n "$config"
|
zsh -n "$config"
|
||||||
done
|
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 '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"
|
grep -q 'apt-get install -y unzip' "$ROOT/install_fnm.sh" || fail "Ubuntu unzip installation is missing"
|
||||||
|
|||||||
Reference in New Issue
Block a user