Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·62 lines (54 loc) · 1.56 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·62 lines (54 loc) · 1.56 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
#!/usr/bin/env bash
#
# Symlinks this repo's dotfiles into the current user's home directory.
# Idempotent: an already-correct link is left untouched. An existing symlink
# (even pointing elsewhere) is overwritten. A real file is backed up to *.orig
# (.orig.1, .orig.2... if already taken) before the link is created.
#
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Map "source path in repo" -> "target name in home"
declare -A LINKS=(
["shell/zshrc"]=".zshrc"
["shell/zshenv"]=".zshenv"
["tmux/tmux.conf"]=".tmux.conf"
["vim/vimrc"]=".vimrc"
["git/gitconfig"]=".gitconfig"
["starship/starship.toml"]=".config/starship.toml"
["herdr/config.toml"]=".config/herdr/config.toml"
["uv/uv.toml"]=".config/uv/uv.toml"
)
link_one() {
local src="$REPO_DIR/$1"
local dst="$HOME/$2"
if [[ ! -e "$src" ]]; then
echo "[SKIP] missing source: $src"
return
fi
# Already the correct link
if [[ -L "$dst" && "$(readlink -f "$dst")" == "$(readlink -f "$src")" ]]; then
echo "[OK] $dst -> $src"
return
fi
if [[ -L "$dst" ]]; then
# Existing symlink pointing elsewhere: overwrite without backup
echo "[DEL] stale link $dst"
rm "$dst"
elif [[ -e "$dst" ]]; then
# Real file: back up to .orig (.orig.1, .orig.2... if already taken)
local bak="$dst.orig"
local i=1
while [[ -e "$bak" ]]; do
bak="$dst.orig.$i"
i=$((i + 1))
done
echo "[BAK] $dst -> $bak"
mv "$dst" "$bak"
fi
mkdir -p "$(dirname "$dst")"
ln -s "$src" "$dst"
echo "[LINK] $dst -> $src"
}
for src in "${!LINKS[@]}"; do
link_one "$src" "${LINKS[$src]}"
done