blob: 8a25c20b48822367776a91c41eaa07cc364418fa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#!/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"
|