feat(config): implement native per-directory configuration support#1556
Draft
Runrioter wants to merge 3 commits into
Draft
feat(config): implement native per-directory configuration support#1556Runrioter wants to merge 3 commits into
Runrioter wants to merge 3 commits into
Conversation
✅ Deploy Preview for spaceship-prompt ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
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_FILEoptions and implements baseline capture + per-directory apply/restore logic. - Hooks per-directory config syncing/apply into
precmdandchpwdto 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 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 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
marked this pull request as draft
June 22, 2026 08:19
Runrioter
force-pushed
the
native-per-direactory-config
branch
from
July 11, 2026 12:48
78cf8bc to
e374460
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds native per-directory configuration support to Spaceship, using project-local
.spaceshiprcfiles instead of relying ondirenv.Motivation
The previous documented approach used
direnvto setSPACESHIP_*variables per directory. That works for some simple cases, but it does not fit Spaceship’s configuration model well.direnvmanages 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 likeSPACESHIP_*_SHOW, this can produce surprising behavior when leaving a directory: a value intended to be disabled globally can be unset bydirenv, 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
direnvA native implementation lets Spaceship manage its own configuration lifecycle:
.spaceshiprcfiles in a deterministic order.direnvexport/unload semantics.direnvremains useful for project environment variables, but Spaceship prompt configuration needs behavior that is aware of Spaceship defaults, section loading, and prompt hooks.