Skip to content

Feature Request: Respect OPENCODE_INSTALL_DIR, XDG_BIN_DIR, $HOME/bin, and Fallback for Installation Path #1124

@ivuorinen

Description

@ivuorinen

Summary

The current OpenCode install script always installs the binary to $HOME/.opencode/bin, which does not respect common standards or user preferences for binary locations. Many modern Linux distributions and user environments prefer XDG-compliant directories or custom bin paths.

Request:
Enhance the installation script to support the following priority order for the installation path:

  1. Use $OPENCODE_INSTALL_DIR if set
  2. Else use $XDG_BIN_DIR if set
  3. Else use $HOME/bin if it exists (or can be created)
  4. Else fallback to $HOME/.opencode/bin

Motivation

  • Standards compliance: The XDG Base Directory Specification is widely used and makes home directories more organized.
  • User flexibility: Many users want to customize where their binaries go, either with $HOME/bin or with XDG variables.
  • Better PATH defaults: Modern distros and shells often include $XDG_BIN_DIR or $HOME/bin in PATH by default.

Current Behavior

The script sets:

INSTALL_DIR=$HOME/.opencode/bin

This does not check for environment variables or user preferences.

Proposed Behavior

Update the install script to:

  1. Use $OPENCODE_INSTALL_DIR if it is set
  2. Else use $XDG_BIN_DIR if it is set
  3. Else use $HOME/bin if it exists or can be created
  4. Else fallback to $HOME/.opencode/bin

Example Implementation

if [ -n "${OPENCODE_INSTALL_DIR:-}" ]; then
    INSTALL_DIR="$OPENCODE_INSTALL_DIR"
elif [ -n "${XDG_BIN_DIR:-}" ]; then
    INSTALL_DIR="$XDG_BIN_DIR"
elif [ -d "$HOME/bin" ] || mkdir -p "$HOME/bin"; then
    INSTALL_DIR="$HOME/bin"
else
    INSTALL_DIR="$HOME/.opencode/bin"
fi
  • The script should also ensure that INSTALL_DIR is added to PATH in the same way as currently, with relevant shell logic.
  • If the chosen INSTALL_DIR is not present in PATH, the script should suggest or attempt to add it, as before.

Benefits

  • More predictable and standards-compliant installations
  • Minimal surprises for users who prefer or require custom bin locations
  • Future-proofs the script for changing Linux desktop conventions

References

Additional Details

  • Please document the new variables (OPENCODE_INSTALL_DIR, XDG_BIN_DIR) in the README for clarity.
  • Consider echoing the chosen install location to the user at the end of the script.
  • For bonus points, warn the user if the chosen path is not present in PATH.

Thank You

This change would greatly improve install experience and compliance with modern Linux standards.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions