-
Notifications
You must be signed in to change notification settings - Fork 265
boxcli: add devbox global shellenv
command
#644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This command prints shell commands that add Devbox packages to the user's PATH. The output is intended to be evaluated in the user's shell rcfile: echo 'eval "$(devbox global shellenv)"' >> ~/.zshrc We don't expand the environment variables in the generated commands so that it's clear to the user what the commands are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool! My main comment is that maybe we should rename this to devbox activate
so it can be more generic. Also we could add a flag that let's the user run this command manually to refresh their shell.
// evaluated twice (once by the "parent" shell and once by the devbox | ||
// shell). Prevent this by making the eval a no-op when we're already | ||
// inside a devbox shell. | ||
if IsDevboxShellEnabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that if a package is installed while in shell, there's not way for the user to update the current shell to make it work. They would have to quit the shell, add the eval statement to their rc files and start it again.
Maybe we add
devbox activate --force
(or --refresh
) or something like that? So we can let the user force the configuration while they are in a devbox shell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative is to have GenerateShellEnv
set a new env variable _DEBOX_SHELL_ENV_SET=1
which is independent of shell. This lets apply this configuration only in cases it hasn't been applied.
We do still run into the issue @ipince brought up that we don't want global packages to supersede local ones. Maybe we splice in the new path instead?
func globalShellenvCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "shellenv", | ||
Short: "Print shell commands that add Devbox packages to your PATH", | ||
Run: func(*cobra.Command, []string) { | ||
fmt.Print(impl.GenerateShellEnv()) | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@loreto had suggested using devbox activate
for this. I like that a bit more because then it's not related to global
but actually a more general command that let's us modify and improve rc configuration over time. Thoughts?
Summary
This command prints shell commands that add Devbox packages to the user's PATH. The output is intended to be evaluated in the user's shell rcfile:
We don't expand the environment variables in the generated commands so that it's clear to the user what the commands are doing.
How was it tested?
Ran
eval $(devbox global shellenv)
withPATH
andXDG_DATA_HOME
set to various values.