#!/usr/bin/env bash # Deploy emacs.el from this repo as ~/.emacs. # # Uses a symlink instead of a copy, so ~/.emacs is ALWAYS the latest # version in this repo -- no reinstall needed after pulls or commits. # Bonus: edits made inside Emacs (e.g. M-x customize writing # custom-set-variables) land in this repo's working tree and show up # in `git diff`, ready to be committed. set -euo pipefail REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SOURCE="$REPO_DIR/emacs.el" TARGET="$HOME/.emacs" BACKUP_DIR="$REPO_DIR/backups" if [ ! -f "$SOURCE" ]; then echo "ERROR: $SOURCE not found" >&2 exit 1 fi # Already installed? if [ "$(readlink "$TARGET" 2>/dev/null || true)" = "$SOURCE" ]; then echo "~/.emacs already points at this repo. Nothing to do." exit 0 fi # Back up any existing config before replacing it if [ -e "$TARGET" ] || [ -L "$TARGET" ]; then mkdir -p "$BACKUP_DIR" BACKUP="$BACKUP_DIR/emacs-$(date +%Y%m%d-%H%M%S)" mv "$TARGET" "$BACKUP" echo "Backed up existing config to $BACKUP" fi ln -s "$SOURCE" "$TARGET" echo "Installed: ~/.emacs -> $SOURCE"