-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·75 lines (58 loc) · 2.13 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·75 lines (58 loc) · 2.13 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
# setup.sh — create symlinks for all dotfiles
#
# Usage:
# sh ~/.dotfiles/setup.sh
#
# Safe to re-run. Existing files are backed up with a .bak suffix before
# being replaced. Already-correct symlinks are skipped without touching them.
set -e
DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
# ── helpers ───────────────────────────────────────────────────────────────────
info() { printf '\033[0;34m=>\033[0m %s\n' "$*"; }
ok() { printf ' \033[0;32mlinked\033[0m %s\n' "$*"; }
skip() { printf ' \033[0;90mskipped\033[0m %s\n' "$*"; }
backup(){ printf ' \033[0;33mbacked up\033[0m %s -> %s\n' "$1" "$2"; }
warn() { printf ' \033[0;33mwarn\033[0m %s\n' "$*" >&2; }
# link <repo-relative-path> <home-relative-destination>
#
# Examples:
# link .zshrc .zshrc ~/.zshrc -> ~/.dotfiles/.zshrc
# link config/nvim .config/nvim ~/.config/nvim -> ~/.dotfiles/config/nvim
link() {
src="$DOTFILES/$1"
dst="$HOME/$2"
if [ ! -e "$src" ]; then
warn "source not found, skipping: $1"
return
fi
# Already pointing at the right place — nothing to do
if [ -L "$dst" ] && [ "$(readlink "$dst")" = "$src" ]; then
skip "$2"
return
fi
# Back up any real file or directory that would be overwritten
if [ -e "$dst" ] && [ ! -L "$dst" ]; then
mv "$dst" "${dst}.bak"
backup "$2" "$2.bak"
fi
# Remove a stale symlink pointing elsewhere
[ -L "$dst" ] && rm "$dst"
mkdir -p "$(dirname "$dst")"
ln -s "$src" "$dst"
ok "$2"
}
# ── symlinks ──────────────────────────────────────────────────────────────────
info "Shell"
link .zshrc .zshrc
link .zprofile .zprofile
info "Git"
link .gitconfig .gitconfig
info "Editors"
link config/nvim .config/nvim
link config/emacs .config/emacs
info "Terminals"
link config/ghostty .config/ghostty
info "Other"
link config/starship.toml .config/starship.toml
info "Done."