Skip to content

Commit 7f7d4a2

Browse files
committed
feat: use XDG_DATA_HOME for install directory
Install binary to $XDG_DATA_HOME/opencode/bin instead of ~/.opencode/bin to follow XDG Base Directory specification. - Defaults to ~/.local/share/opencode/bin if XDG_DATA_HOME is not set - Migrates existing installations from ~/.opencode/bin automatically - Compatible with existing upgrade detection logic Fixes anomalyco#5176
1 parent 6a4ca92 commit 7f7d4a2

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎install‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ else
9999
fi
100100
fi
101101

102-
INSTALL_DIR=$HOME/.opencode/bin
102+
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
103+
INSTALL_DIR="$XDG_DATA_HOME/opencode/bin"
104+
LEGACY_DIR="$HOME/.opencode/bin"
103105
mkdir -p "$INSTALL_DIR"
104106

105107
if [ -z "$requested_version" ]; then
@@ -148,6 +150,19 @@ check_version() {
148150
fi
149151
}
150152

153+
migrate_legacy_installation() {
154+
# Migrate from ~/.opencode/bin to XDG location if needed
155+
if [ -d "$LEGACY_DIR" ] && [ "$LEGACY_DIR" != "$INSTALL_DIR" ]; then
156+
if [ -f "$LEGACY_DIR/opencode" ]; then
157+
print_message info "${MUTED}Migrating from ${NC}$LEGACY_DIR${MUTED} to ${NC}$INSTALL_DIR"
158+
mv "$LEGACY_DIR/opencode" "$INSTALL_DIR/opencode" 2>/dev/null || true
159+
# Try to clean up empty directories
160+
rmdir "$LEGACY_DIR" 2>/dev/null || true
161+
rmdir "$HOME/.opencode" 2>/dev/null || true
162+
fi
163+
fi
164+
}
165+
151166
unbuffered_sed() {
152167
if echo | sed -u -e "" >/dev/null 2>&1; then
153168
sed -nu "$@"
@@ -259,6 +274,7 @@ download_and_install() {
259274
}
260275

261276
check_version
277+
migrate_legacy_installation
262278
download_and_install
263279

264280

0 commit comments

Comments
 (0)