You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
- Added a small command that updates the PATH to use devbox packages
when users integration direnv and cd into a devbox project.
- Added guidelines on how to setup `direnv` and integrate with devbox.
## How was it tested?
- Have direnv installed and hooked to your shell
- Create an empty directory
- `devbox init`
- `devbox shell` then `exit`
- `touch .envrc` then put the following inside it:
```bash
use_devbox() {
watch_file devbox.json
eval $(devbox setup-direnv)
}
use devbox
```
- `direnv allow`
- Compare running `which python3` or `which go` from inside the
directory and outside
Copy file name to clipboardExpand all lines: boxcli/shell.go
+34-20Lines changed: 34 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -13,42 +13,56 @@ import (
13
13
"go.jetpack.io/devbox"
14
14
)
15
15
16
+
typeshellFlagsstruct {
17
+
PrintEnvbool
18
+
}
19
+
16
20
funcShellCmd() *cobra.Command {
21
+
flags:=&shellFlags{}
17
22
command:=&cobra.Command{
18
23
Use: "shell [<dir>] -- [<cmd>]",
19
24
Short: "Start a new shell or run a command with access to your packages",
20
25
Long: "Start a new shell or run a command with access to your packages. \nIf invoked without `cmd`, this will start an interactive shell based on the devbox.json in your current directory, or the directory provided with `dir`. \nIf invoked with a `cmd`, this will start a shell based on the devbox.json provided in `dir`, run the command, and then exit.",
21
26
Args: validateShellArgs,
22
27
PersistentPreRunE: nixShellPersistentPreRunE,
23
-
RunE: runShellCmd,
28
+
RunE: runShellCmd(flags),
24
29
}
30
+
command.Flags().BoolVar(
31
+
&flags.PrintEnv, "print-env", false, "Print script to setup shell environment")
[direnv](https://direnv.net) is an open source environment management tool that allows setting unique environment variables per directory in your file system. This guide covers how to configure direnv to seemlessly work with a devbox project.
9
+
10
+
### Prerequisites
11
+
* Install direnv and hook it to your shell. Follow [this guide](https://direnv.net/#basic-installation) if you haven't done it.
12
+
13
+
### Setting up with Devbox Shell and direnv
14
+
15
+
Note: If you already have a devbox project you may skip to step 3.
16
+
17
+
1.`devbox init` if you don't have a devbox.json in the root directory of your project.
18
+
2.`devbox shell -- 'ls'` to activate devbox shell temporarily and make sure dependencies mentioned in your devbox.json are installed.
19
+
3. Create a new file, name it `.envrc` and put the following snippet inside it:
20
+
```bash
21
+
use_devbox() {
22
+
watch_file devbox.json
23
+
eval$(devbox shell --print-env)
24
+
}
25
+
use devbox
26
+
```
27
+
4. Run `direnv allow` to give permission to `direnv` to setup your environment variables.
28
+
5. At this point, your project directory is setup so that every time you `cd` into it, the binaries from your devbox shell will be used. To test this, you can compare running `which python3` from your project directory and outside.
29
+
30
+
### Global settings for direnv
31
+
32
+
Note that every time changes are made to `devbox.json` via `devbox add ...`, `devbox rm ...` or directly editing the file, requires `direnv allow` to run so that `direnv` can setup the new changes.
33
+
34
+
Alternatively, a project directory can be whitelisted so that changes will be automatically picked up by `direnv`. This is done by adding following snippet to direnv config file typically at `~/.config/direnv/direnv.toml`. You can create the file and directory if it doesn't exist.
35
+
36
+
```toml
37
+
[whitelist]
38
+
prefix = [ "/absolute/path/to/project" ]
39
+
40
+
```
41
+
<!-- TODO: add steps for vscode integration -->
42
+
43
+
If this guide is missing something, feel free to contribute by opening a [pull request](https://github.com/jetpack-io/devbox/pulls) in Github.
0 commit comments