diff options
Diffstat (limited to 'install.sh')
| -rwxr-xr-x | install.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..8a25c20 --- /dev/null +++ b/install.sh @@ -0,0 +1,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" |
