Repository navigation
Expand file tree
/
Copy pathsetup
More file actions
executable file
·46 lines (38 loc) · 1.6 KB
/
Copy pathsetup
File metadata and controls
executable file
·46 lines (38 loc) · 1.6 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
#!/usr/bin/env bash
set -euo pipefail
DIRNAME=$(cd "$(dirname "$0")" && pwd)
PACKAGES=('agents' 'claude' 'codex' 'config' 'emacs' 'git' 'ruby' 'tmux' 'vim' 'zsh')
if ! command -v stow >/dev/null 2>&1; then
echo "GNU Stow 2.4.0 or newer is required; see TROUBLESHOOTING.md, then rerun ./setup" >&2
exit 1
fi
STOW_VERSION=$(stow --version | awk 'NR == 1 { print $NF }')
if [[ ! "$STOW_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] ||
(( BASH_REMATCH[1] < 2 || (BASH_REMATCH[1] == 2 && BASH_REMATCH[2] < 4) )); then
echo "GNU Stow 2.4.0 or newer is required (found $STOW_VERSION); see TROUBLESHOOTING.md, then rerun ./setup" >&2
exit 1
fi
echo "Restowing dotfiles..."
if [ "$(uname -s)" = "Darwin" ]; then
cat "$DIRNAME/.aliases/osx" "$DIRNAME/.aliases/shared" > "$HOME/.aliases"
else
cat "$DIRNAME/.aliases/linux" "$DIRNAME/.aliases/shared" > "$HOME/.aliases"
fi
if [ -L "$HOME/.claude/CLAUDE.md" ] && [ "$(readlink "$HOME/.claude/CLAUDE.md")" = "$HOME/.agents/AGENTS.md" ]; then
unlink "$HOME/.claude/CLAUDE.md"
fi
if [ -L "$HOME/.codex/AGENTS.md" ] && [ "$(readlink "$HOME/.codex/AGENTS.md")" = "$HOME/.claude/CLAUDE.md" ]; then
unlink "$HOME/.codex/AGENTS.md"
fi
stow --dir="$DIRNAME" --target="$HOME" --restow "${PACKAGES[@]}"
OPENCODE_DIR="$HOME/.config/opencode"
for file in package.json package-lock.json; do
target="$OPENCODE_DIR/$file"
source="$DIRNAME/config/.config/opencode/$file"
if [ -f "$target" ] && [ ! -L "$target" ]; then
backup="$target.local"
[ -e "$backup" ] && backup="$target.$(date +%Y%m%d%H%M%S).local"
mv "$target" "$backup"
fi
ln -sfn "$source" "$target"
done