From 7f7d4a2b37c3430d430b4885177ca36eae9034fa Mon Sep 17 00:00:00 2001 From: dane Date: Sat, 6 Dec 2025 16:05:12 -0500 Subject: [PATCH] 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 #5176 --- install | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/install b/install index c6f209734..64ae56671 100755 --- a/install +++ b/install @@ -99,7 +99,9 @@ else fi fi -INSTALL_DIR=$HOME/.opencode/bin +XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" +INSTALL_DIR="$XDG_DATA_HOME/opencode/bin" +LEGACY_DIR="$HOME/.opencode/bin" mkdir -p "$INSTALL_DIR" if [ -z "$requested_version" ]; then @@ -148,6 +150,19 @@ check_version() { fi } +migrate_legacy_installation() { + # Migrate from ~/.opencode/bin to XDG location if needed + if [ -d "$LEGACY_DIR" ] && [ "$LEGACY_DIR" != "$INSTALL_DIR" ]; then + if [ -f "$LEGACY_DIR/opencode" ]; then + print_message info "${MUTED}Migrating from ${NC}$LEGACY_DIR${MUTED} to ${NC}$INSTALL_DIR" + mv "$LEGACY_DIR/opencode" "$INSTALL_DIR/opencode" 2>/dev/null || true + # Try to clean up empty directories + rmdir "$LEGACY_DIR" 2>/dev/null || true + rmdir "$HOME/.opencode" 2>/dev/null || true + fi + fi +} + unbuffered_sed() { if echo | sed -u -e "" >/dev/null 2>&1; then sed -nu "$@" @@ -259,6 +274,7 @@ download_and_install() { } check_version +migrate_legacy_installation download_and_install