Files
dotemacs/bin/link-machine.sh
T
Willem van den Ende 2bf149a2e8 refactor(init): give init.el one owner per machine
Doom's `doom!' takes a single module list, so this file cannot be shared:
the two machines want different module sets (vertico + popup + workspaces
here, ivy + dashboard + doom-quit there), and the mac list still carries
pre-3.0 names that this Doom rejects.  Instead of merging 143 lines of it,
each machine keeps its own copy:

  linux/init.el   from linux-adopt, verbatim (cmp: identical)
  mac/init.el     the previous root init.el, verbatim (cmp: identical)

The root init.el is now an *untracked* symlink into whichever directory
matches the machine, created by bin/link-machine.sh.  It has to be
untracked: one branch is shared by both machines, and a tracked symlink can
only have one target.  /init.el is gitignored so a stray link can never be
committed and clobber the other machine.

Verified:
  - link resolves: file-truename init.el -> .../linux/init.el
  - the file parses (check-parens) through the link
  - sh -n clean; unknown-machine path exits 1 with a message
  - git status clean apart from this commit (symlink is ignored)

On the mac, after pulling: ./bin/link-machine.sh && doom sync

Caveats, all consequences of the link being untracked:
  - a fresh clone has no init.el until you run the script
  - `git clean -xfd' deletes it; re-run the script
  - Emacs' byte-compiler would write init.elc next to the link (repo root);
    harmless here since *.elc is ignored and the target's mtime wins when
    the .el has been edited

config.el and packages.el stay shared at the root for now: their content is
mostly common, and three-way merges are worth more there than isolation.
That is also why AGENTS.md, snippets/ and qwan/ stay where they are.
2026-11-03 13:13:26 +00:00

65 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# link-machine.sh --- point this checkout's entry files at the right machine dir
#
# The repo holds one directory per machine (linux/, mac/) because Doom's
# init.el cannot be reconciled across them: `doom!' takes a single module
# list. Doom still insists on finding init.el at $DOOMDIR, so each machine
# gets an untracked symlink at the repo root:
#
# init.el -> linux/init.el (on GNU/Linux)
# init.el -> mac/init.el (on macOS)
#
# Those root files are gitignored on purpose: one branch is shared by both
# machines, so a tracked root symlink could only ever point at one of them.
# Consequence: a fresh clone has no init.el until you run this, and
# `git clean -xfd' will delete the links. Re-run this script either way.
#
# Only files that have actually been split out are linked. config.el and
# packages.el are still shared at the repo root; the day mac/config.el
# appears, this script links it too, no edit needed.
#
# Usage: bin/link-machine.sh [linux|mac] (auto-detects via uname)
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
if [ $# -ge 1 ]; then
machine=$1
else
case $(uname -s) in
Darwin) machine=mac ;;
Linux) machine=linux ;;
*) echo "link-machine.sh: unsupported system $(uname -s); pass linux or mac" >&2
exit 1 ;;
esac
fi
case $machine in
linux|mac) ;;
*) echo "link-machine.sh: unknown machine '$machine' (want linux or mac)" >&2
exit 1 ;;
esac
if [ ! -d "$root/$machine" ]; then
echo "link-machine.sh: no $machine/ directory in $root" >&2
exit 1
fi
linked=0
for f in init.el config.el packages.el; do
if [ -f "$root/$machine/$f" ]; then
# relative link, so the checkout can be moved without relinking
ln -sfn "$machine/$f" "$root/$f"
echo "linked $f -> $machine/$f"
linked=$((linked + 1))
fi
done
if [ "$linked" -eq 0 ]; then
echo "link-machine.sh: nothing to link for $machine -- no entry files in $machine/" >&2
exit 1
fi
echo "done. next: doom sync"