Skip to content

feat(config): implement native per-directory configuration support#1556

Draft
Runrioter wants to merge 3 commits into
spaceship-prompt:masterfrom
Runrioter:native-per-direactory-config
Draft

feat(config): implement native per-directory configuration support#1556
Runrioter wants to merge 3 commits into
spaceship-prompt:masterfrom
Runrioter:native-per-direactory-config

Conversation

@Runrioter

Copy link
Copy Markdown
Member

Description

This PR adds native per-directory configuration support to Spaceship, using project-local .spaceshiprc files instead of relying on direnv.

Motivation

The previous documented approach used direnv to set SPACESHIP_* variables per directory. That works for some simple cases, but it does not fit Spaceship’s configuration model well.

direnv manages environment variables by exporting, unsetting, or emptying values as the current directory changes. Spaceship options are not just ordinary process environment values; many section defaults are initialized from Zsh variables and often treat an unset or empty value as “use the section default.” For options like SPACESHIP_*_SHOW, this can produce surprising behavior when leaving a directory: a value intended to be disabled globally can be unset by direnv, then effectively fall back to the section default.

This is especially fragile for prompt configuration because prompt rendering happens during shell hooks, where timing matters. The prompt needs a stable baseline configuration and a predictable restore/apply cycle.

Why native instead of direnv

A native implementation lets Spaceship manage its own configuration lifecycle:

  • It can capture the user’s global Spaceship configuration as a baseline.
  • It can restore that baseline before applying directory-local overrides.
  • It can apply parent-to-child .spaceshiprc files in a deterministic order.
  • It avoids depending on direnv export/unload semantics.
  • It keeps prompt configuration inside Spaceship instead of coupling it to a general-purpose environment manager.
  • It prevents local project settings from leaking into unrelated directories.

direnv remains useful for project environment variables, but Spaceship prompt configuration needs behavior that is aware of Spaceship defaults, section loading, and prompt hooks.

Copilot AI review requested due to automatic review settings June 18, 2026 09:24
@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for spaceship-prompt ready!

Name Link
🔨 Latest commit e374460
🔍 Latest deploy log https://app.netlify.com/projects/spaceship-prompt/deploys/6a523baebbde3a0009d8781f
😎 Deploy Preview https://deploy-preview-1556--spaceship-prompt.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds native per-directory configuration support by sourcing project-local .spaceshiprc files (optionally enabled) and applying/restoring directory overrides deterministically via Zsh hooks.

Changes:

  • Introduces SPACESHIP_PER_DIRECTORY_CONFIG / SPACESHIP_PER_DIRECTORY_CONFIG_FILE options and implements baseline capture + per-directory apply/restore logic.
  • Hooks per-directory config syncing/apply into precmd and chpwd to ensure directory changes update prompt configuration predictably.
  • Adds/updates tests and documentation for the new feature.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/config.zsh Implements baseline capture/restore and parent-to-child .spaceshiprc discovery + sourcing.
lib/hooks.zsh Calls per-directory config sync/apply from precmd and chpwd.
spaceship.zsh Adds new config defaults and removes a duplicate autoload line.
tests/config.test.zsh Adds shunit2 coverage for per-directory config behavior (stacking, restore, reload sections).
tests/hooks.test.zsh Extends hook tests to validate per-directory apply on chpwd.
docs/config/prompt.md Documents the two new configuration options in the prompt options table.
docs/advanced/per-directory-config.md Replaces direnv-based docs with native per-directory config docs (one grammar nit noted).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/advanced/per-directory-config.md Outdated
Copilot AI review requested due to automatic review settings June 18, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread lib/config.zsh
Comment on lines +105 to +110
for name in ${(ok)parameters[(I)SPACESHIP_*]}; do
spaceship::config::is_managed "$name" || continue
(( ${+_SPACESHIP_CONFIG_BASELINE[$name]} )) && continue

unset "$name" 2>/dev/null
done
Comment thread tests/config.test.zsh
Comment on lines +147 to +160
test_per_directory_config_reloads_sections_when_order_changes() {
local repo="$SHUNIT_TMPDIR/config/order"
mkdir -p "$repo"
print "SPACESHIP_PROMPT_ORDER=(user git)" > "$repo/.spaceshiprc"

SPACESHIP_PER_DIRECTORY_CONFIG=true
spaceship::config::capture_baseline

cd "$repo"
spaceship::config::apply_per_directory

assertEquals "should reload sections after prompt order changes" 1 "$LOAD_SECTIONS_CALLS"
assertEquals "should keep local prompt order" "user git" "${(j: :)SPACESHIP_PROMPT_ORDER}"
}
@Runrioter
Runrioter marked this pull request as draft June 22, 2026 08:19
@Runrioter
Runrioter force-pushed the native-per-direactory-config branch from 78cf8bc to e374460 Compare July 11, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants