-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·72 lines (62 loc) · 1.72 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·72 lines (62 loc) · 1.72 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
#!/usr/bin/env bash
# install.sh - symlink dotfiles into $HOME and (optionally) install Brewfile.
#
# Idempotent: re-running is safe. Existing files are backed up to
# ~/.bloat-backup-<timestamp>/ before being replaced.
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_DIR="$HOME/.bloat-backup-$(date +%Y%m%d-%H%M%S)"
dotfiles=(
.zshrc
.gitconfig
)
claude_files=(
.claude/CLAUDE.md
)
backup_then_link() {
local src="$REPO_DIR/$1"
local dst="$HOME/$1"
if [[ -e "$dst" && ! -L "$dst" ]]; then
mkdir -p "$BACKUP_DIR/$(dirname "$1")"
mv "$dst" "$BACKUP_DIR/$1"
echo " backed up existing $dst -> $BACKUP_DIR/$1"
elif [[ -L "$dst" ]]; then
rm "$dst"
fi
mkdir -p "$(dirname "$dst")"
ln -s "$src" "$dst"
echo " linked $src -> $dst"
}
echo "==> Linking dotfiles"
for f in "${dotfiles[@]}"; do
backup_then_link "$f"
done
echo "==> Linking Claude rules"
for f in "${claude_files[@]}"; do
backup_then_link "$f"
done
echo "==> Linking bin/"
mkdir -p "$HOME/.local/bin"
for script in "$REPO_DIR"/bin/*; do
if [[ -f "$script" ]]; then
local_name="$(basename "$script")"
target="$HOME/.local/bin/$local_name"
[[ -L "$target" ]] && rm "$target"
ln -s "$script" "$target"
chmod +x "$script"
echo " linked $script -> $target"
fi
done
if [[ "${1:-}" == "--brew" ]]; then
echo "==> Installing Brewfile"
if ! command -v brew >/dev/null; then
echo " brew not found; install from https://brew.sh first"
exit 1
fi
brew bundle --file="$REPO_DIR/Brewfile"
fi
if [[ -d "$BACKUP_DIR" ]]; then
echo
echo "Backups: $BACKUP_DIR"
fi
echo "Done. Open a new shell."