Repository navigation
Expand file tree
/
Copy pathsetup_opencode_config.sh
More file actions
executable file
·111 lines (91 loc) · 3.1 KB
/
Copy pathsetup_opencode_config.sh
File metadata and controls
executable file
·111 lines (91 loc) · 3.1 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
set -euo pipefail
DOTFILES_OPENCODE="$HOME/dotfiles/opencode"
OPENCODE_DIR="$HOME/.config/opencode"
CONFIG_FILES=(
"opencode.jsonc"
"dcp.jsonc"
"AGENTS.md"
)
CONFIG_DIRS=(
"agents"
"skills"
)
echo "Setting up opencode configuration symlinks..."
mkdir -p "$OPENCODE_DIR"
for file in "${CONFIG_FILES[@]}"; do
SOURCE="$DOTFILES_OPENCODE/$file"
TARGET="$OPENCODE_DIR/$file"
if [ -e "$SOURCE" ]; then
if [ -e "$TARGET" ] && [ ! -L "$TARGET" ]; then
echo "Backing up existing $file to $file.backup"
mv "$TARGET" "$TARGET.backup"
fi
[ -L "$TARGET" ] && rm "$TARGET"
echo "Symlinking $file"
ln -s "$SOURCE" "$TARGET"
else
echo "Warning: $SOURCE not found, skipping"
fi
done
# commands/ is a real directory of per-file symlinks so commands from the
# private dotfiles repo (if installed) can live alongside the public ones.
COMMANDS_DIR="$OPENCODE_DIR/commands"
mkdir -p "$COMMANDS_DIR"
if [ -L "$COMMANDS_DIR" ]; then
rm "$COMMANDS_DIR"
fi
for cmd_file in "$DOTFILES_OPENCODE/commands"/*.md "$DOTFILES_OPENCODE/commands"/.internal/*.md; do
[ -f "$cmd_file" ] || continue
name="$(basename "$cmd_file")"
sub=""
case "$cmd_file" in
*/.internal/*) sub=".internal/" ;;
esac
target="$COMMANDS_DIR/$sub$name"
mkdir -p "$COMMANDS_DIR/$sub"
[ -L "$target" ] && rm "$target"
echo "Symlinking command $sub$name"
ln -s "$cmd_file" "$target"
done
# rtk powers the token-saving shell-command rewrites in plugins/rtk.ts.
# https://github.com/rtk-ai/rtk
if ! command -v rtk >/dev/null 2>&1; then
echo "rtk not found — installing it from https://github.com/rtk-ai/rtk"
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh ||
echo "Warning: rtk install failed — install it manually: https://github.com/rtk-ai/rtk"
fi
# plugins/ is a real directory of per-file symlinks so plugins from the
# private dotfiles repo (if installed) can live alongside the public ones.
PLUGINS_DIR="$OPENCODE_DIR/plugins"
if [ -L "$PLUGINS_DIR" ]; then
rm "$PLUGINS_DIR"
fi
mkdir -p "$PLUGINS_DIR"
for plugin_file in "$DOTFILES_OPENCODE/plugins"/*.ts "$DOTFILES_OPENCODE/plugins"/*.js; do
[ -f "$plugin_file" ] || continue
target="$PLUGINS_DIR/$(basename "$plugin_file")"
[ -L "$target" ] && rm "$target"
echo "Symlinking plugin $(basename "$plugin_file")"
ln -s "$plugin_file" "$target"
done
for dir in "${CONFIG_DIRS[@]}"; do
SOURCE="$DOTFILES_OPENCODE/$dir"
TARGET="$OPENCODE_DIR/$dir"
if [ -d "$SOURCE" ]; then
if [ -d "$TARGET" ] && [ ! -L "$TARGET" ]; then
echo "Backing up existing $dir/ to $dir.backup/"
mv "$TARGET" "$TARGET.backup"
fi
[ -L "$TARGET" ] && rm "$TARGET"
echo "Symlinking $dir/"
ln -s "$SOURCE" "$TARGET"
else
echo "Warning: $SOURCE not found, skipping"
fi
done
echo ""
echo "opencode configuration setup complete!"
echo ""
echo "Symlinked files:"
find "$OPENCODE_DIR" -maxdepth 1 -type l -lname "*$DOTFILES_OPENCODE*" -ls