Skip to content

[RFC][direnv-inspired] introduce export and hook commands, use in devbox shell, global and direnv #1172

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

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Jun 16, 2023

Summary

See #1156 for overall motivation.

In this PR:

  1. Turn off adding bin-wrappers path to $PATH from devbox shellenv.
  2. We add commands devbox hook and devbox export, analogous to direnv hook and direnv export.
    • export is an alias of shellenv, and is hidden
    • hook registers a shell prompt hook that wil call eval $(devbox export)
  3. During devbox shell, we add eval $(devbox hook) to the generated shellrc file.
  4. During direnv, the code is essentially unchanged except callingdevbox export instead of devbox shellenv.
  5. For global, the users are currently expected to add eval $(devbox global hook <shell>)

RFC proposal to roll out:

  1. I don't think we need devbox export. We can continue with devbox shellenv.
  2. We can remove devbox hook entirely: in the generated shellrc, we can inline the code of the hook that calls devbox export.
  3. We can introduce devbox global activate to have the functionality that devbox global hook has in this PR.
  • activate is a generic word, enabling us to change its functionality under-the-hood. It would save us the dilemma we have with this PR about how to make users change their shellrc code from devbox global shellenv to devbox global hook.
  • We can make devbox global shellenv an alias of devbox global activate. This would save users from needing to update their personal shellrc files.

How was it tested?

Added a feature flag: DEVBOX_FEATURE_PROMPT_HOOK=1.

Did some basic testing:

  • project:
    • devbox shell and then edited devbox.json to add a new package, and saw the new package being installed prior to next prompt being displayed.
    • devbox run -- iex -S mix worked as expected, since we can turn off the bin-wrappers.
  • global:
    • added devbox global hook | source to my fish shell.
    • devbox global ls worked.
    • devbox global add <package> worked as before.

Note: this PR adds the basic functionality, but the feature is not yet robust. For a full list of pending scenarios that must work, please refer to the (internal) notion doc.

Copy link
Collaborator Author

savil commented Jun 16, 2023

@savil savil force-pushed the savil/direnv-inspired-shellenv branch from 8975339 to e24ad15 Compare June 16, 2023 22:47
@savil savil force-pushed the savil/direnv-inspired-shellenv-2 branch from 95ab2db to a9c13a8 Compare June 16, 2023 22:47
@savil savil force-pushed the savil/direnv-inspired-shellenv branch from e24ad15 to 61a3bfd Compare June 16, 2023 23:45
@savil savil force-pushed the savil/direnv-inspired-shellenv-2 branch 3 times, most recently from 602db68 to 5f9367c Compare June 17, 2023 00:28
@savil savil changed the title [direnv-inspired] add export and hook commands, and hook up shell, global and direnv [direnv-inspired] introduce export and hook commands, use in devbox shell, global and direnv Jun 17, 2023
@savil savil force-pushed the savil/direnv-inspired-shellenv-2 branch from 5f9367c to e23f447 Compare June 17, 2023 00:51
@savil savil changed the title [direnv-inspired] introduce export and hook commands, use in devbox shell, global and direnv [RFC][direnv-inspired] introduce export and hook commands, use in devbox shell, global and direnv Jun 17, 2023
@savil savil requested review from gcurtis and loreto June 17, 2023 00:53
@savil savil marked this pull request as ready for review June 17, 2023 00:53
Copy link
Contributor

@loreto loreto left a comment

Choose a reason for hiding this comment

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

LGTM

func hookCmd() *cobra.Command {
flags := hookFlags{}
cmd := &cobra.Command{
Use: "hook [shell]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Another possible name for this command is activate (it's what https://github.com/jdxcode/rtx uses)

Leave as hook, and let's get the PR in, but I wanna get John's thoughts on which one is the better name, before we remove the feature flag and start transitioning people.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, agree on activate. Please see my RFC proposal in the PR summary for reasons why I like it...

@savil savil force-pushed the savil/direnv-inspired-shellenv branch from 61a3bfd to 751628e Compare June 26, 2023 16:03
@savil savil force-pushed the savil/direnv-inspired-shellenv-2 branch from e23f447 to f4dc79b Compare June 26, 2023 16:03
Base automatically changed from savil/direnv-inspired-shellenv to main June 26, 2023 18:14
@savil savil force-pushed the savil/direnv-inspired-shellenv-2 branch from f4dc79b to cc2aff7 Compare June 26, 2023 18:23
@savil savil merged commit 9e3638f into main Jun 26, 2023
@savil savil deleted the savil/direnv-inspired-shellenv-2 branch June 26, 2023 19:05
savil added a commit that referenced this pull request Jun 28, 2023
## Summary

Minor followup to #1172

## How was it tested?
savil added a commit that referenced this pull request Jun 29, 2023
…e in devbox shell, global and direnv (#1172)"

This reverts commit 9e3638f.
savil added a commit that referenced this pull request Jun 29, 2023
…e in devbox shell, global and direnv (#1172)" (#1233)

## Summary

Reverts #1172.

While we feel architecturally this is a better approach, it would
introduce some
non-trivial risk.

For the moment, bin-wrappers seem to have stabilized so we'll punt on
this, and
circle back to it later.

## How was it tested?

compiles

- [ ] testscripts should pass
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