fix(direnv): set DEVBOX_SHELL_ENABLED when entering env via shellenv --init-hook#2861
Open
mikeland73 wants to merge 1 commit into
Open
fix(direnv): set DEVBOX_SHELL_ENABLED when entering env via shellenv --init-hook#2861mikeland73 wants to merge 1 commit into
mikeland73 wants to merge 1 commit into
Conversation
…--init-hook The direnv integration loads the Devbox environment by evaluating `devbox shellenv --init-hook`, but that path never set DEVBOX_SHELL_ENABLED. As a result `$DEVBOX_SHELL_ENABLED` was empty in direnv-activated shells, contradicting the documented behavior that it is set to 1 whenever the environment is loaded. Set DEVBOX_SHELL_ENABLED=1 in EnvExports when init hooks are run, mirroring what Shell() and RunScript() already do. The flag is gated on RunHooks so that the global integration (`devbox global shellenv`, which does not run init hooks) does not set it in every shell and break shell-inception detection. Adds a regression testscript asserting that `devbox shellenv --init-hook` exports the variable while plain `devbox shellenv` does not. Fixes #2746
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the direnv activation path so that DEVBOX_SHELL_ENABLED is exported when entering a Devbox environment via devbox shellenv --init-hook, aligning behavior with the documented env-var semantics and resolving #2746.
Changes:
- Set
DEVBOX_SHELL_ENABLED=1insideDevbox.EnvExports()whenRunHooksis enabled (i.e.,shellenv --init-hook), while leaving plainshellenv/global shellenvunchanged. - Add a regression testscript to assert
--init-hookexports the variable and plainshellenvdoes not.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
internal/devbox/devbox.go |
Exports DEVBOX_SHELL_ENABLED when EnvExports is invoked with init hooks enabled (RunHooks=true). |
testscripts/shell/shellenv_init_hook.test.txt |
Adds coverage to prevent regressions for shellenv --init-hook vs plain shellenv. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes #2746.
When using
direnvto load a Devbox environment,$DEVBOX_SHELL_ENABLEDwas never set, even though the documentation states it is "automatically set to 1 when you start a shell, run a script, or start services."The direnv integration loads the environment by evaluating
devbox shellenv --init-hook(seeinternal/devbox/generate/tmpl/envrcContent.tmpl). That code path runs throughDevbox.EnvExports, which — unlikeShell()andRunScript()— never setDEVBOX_SHELL_ENABLED. Soecho $DEVBOX_SHELL_ENABLEDprinted nothing in a direnv-activated shell.Fix
Set
DEVBOX_SHELL_ENABLED=1inEnvExportswhen init hooks are run, mirroring whatShell()andRunScript()already do.The assignment is gated on
RunHookson purpose:devbox shellenv --init-hook(RunHooks = true) → now sets the variable. ✅devbox global shellenvruns in every shell and does not pass--init-hook(RunHooks = false) → still does not set the variable, so shell-inception detection (which relies onDEVBOX_SHELL_ENABLED) keeps working in every shell. ✅devbox shellenvis likewise unaffected.How was it tested?
go build ./...andgo vet ./internal/devbox/pass.testscripts/shell/shellenv_init_hook.test.txtasserting that:devbox shellenv --init-hookexportsDEVBOX_SHELL_ENABLED="1", anddevbox shellenvdoes not export it.cc @miklschmidt (issue reporter)
Generated by Claude Code