Skip to content

feat: migrate to XDG/FHS install locations#23

Open
ukanga wants to merge 3 commits into
pld:mainfrom
ukanga:issue-22-install-locations
Open

feat: migrate to XDG/FHS install locations#23
ukanga wants to merge 3 commits into
pld:mainfrom
ukanga:issue-22-install-locations

Conversation

@ukanga
Copy link
Copy Markdown
Collaborator

@ukanga ukanga commented May 10, 2026

Closes #21.

Summary

  • Binary moves from ~/.wt/wt (shell alias) to ~/.local/bin/wt (on PATH)
  • Global config moves from ~/.wt/config.toml to $XDG_CONFIG_HOME/wt/config.toml (default ~/.config/wt/)
  • Session state moves from ~/.wt/sessions.json to $XDG_STATE_HOME/wt/sessions.json (default ~/.local/state/wt/)
  • macOS gets the same XDG paths, not ~/Library/Application Support/

Changes

src/config.rs / src/session.rs: Hand-rolled xdg_config_home() / xdg_state_home() helpers (avoids dirs::config_dir() / dirs::state_dir() which return Apple paths on macOS). Legacy ~/.wt/ paths are read as a fallback with a one-time stderr notice; writes always go to the new locations.

install.sh: Installs to ~/.local/bin/wt by default. --system flag installs to /usr/local/bin/wt (with sudo). Alias-writing block removed entirely. Re-running the installer migrates legacy files, removes stale shell aliases from rc files, and cleans up ~/.wt/ if empty. Prints a one-line PATH instruction if the install dir is not on $PATH (macOS).

README.md: Updated Installation and Configuration sections.

Test plan

  • Fresh install (no ~/.wt/): binary at ~/.local/bin/wt, nothing written under ~/.wt/
  • ./install.sh --system installs to /usr/local/bin/wt
  • New config/state files land at ~/.config/wt/ and ~/.local/state/wt/
  • Existing user re-runs installer: files migrated, ~/.wt/ removed, aliases stripped from rc files, which wt resolves to new path
  • Re-running installer after migration is idempotent (exit 0, no duplicates)
  • XDG_CONFIG_HOME / XDG_STATE_HOME env vars honoured
  • Legacy-only user (no re-install): wt reads from ~/.wt/ with deprecation notice
  • cargo test passes (60 unit + integration tests including new XDG and legacy-fallback tests)

@ukanga ukanga force-pushed the issue-22-install-locations branch 3 times, most recently from 50b8b72 to db2ba0f Compare May 10, 2026 18:16
ukanga added 3 commits May 10, 2026 21:16
Move global config to $XDG_CONFIG_HOME/wt/config.toml (default
~/.config/wt/) and session state to $XDG_STATE_HOME/wt/sessions.json
(default ~/.local/state/wt/).

XDG helpers use hand-rolled env-var logic rather than dirs::config_dir()
/ dirs::state_dir(), which return Apple paths on macOS. Relative values
for XDG_CONFIG_HOME and XDG_STATE_HOME are rejected per the XDG Base
Directory spec and silently fall back to the defaults.

Legacy ~/.wt/ paths are still read as a fallback with a one-time stderr
notice, so existing users keep working without re-running the installer.
Directory creation only happens on write; the read path resolves the
path without touching the filesystem.

Env-mutating tests are serialised through a crate-level Mutex to prevent
races under cargo's parallel test runner.
…m flag

Install to ~/.local/bin/wt (on PATH by default on modern Linux) instead
of ~/.wt/wt behind a shell alias. Drop alias-writing entirely. Add a
--system flag to install to /usr/local/bin/wt with sudo.

Directory creation uses the same privilege path as the binary copy, so
--system never hits a permissions error before reaching sudo.

When re-run on a machine with the old layout the installer:
- removes the comment+alias block it previously wrote from shell rc files
- deletes ~/.wt/wt
- moves ~/.wt/config.toml and ~/.wt/sessions.json to their XDG locations
- removes ~/.wt/ if it is then empty

Alias removal uses awk (portable across GNU/Linux and BSD/macOS) and only
deletes the exact two-line block the old installer wrote; user-defined
aliases are never touched. The helper is a top-level function, not nested
inside migrate_legacy.

The temp file used for release downloads is guarded by an EXIT trap so
it is always cleaned up even if curl or the install step fails.

XDG_CONFIG_HOME and XDG_STATE_HOME are validated for absolute paths
before use, matching the Rust helpers; relative or empty values fall back
to $HOME/.config and $HOME/.local/state.

If the install directory is not on PATH (common on macOS) the installer
prints a single instruction line and does not modify any shell rc file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install binary, config, and state to standard XDG / FHS locations

1 participant