Skip to content

Commit f94da94

Browse files
authored
[direnv] Fix direnv fish support (#1636)
## Summary Adding alias to `direnv` environment is causing problems in fish and doesn't work anyway (because direnv doesn't support aliases) ## How was it tested? * For both zsh and fish * Started shell * activated direnv hook * cd to devbox directory * confirmed environment was actice * installed package and tested it
1 parent 165c3f2 commit f94da94

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

internal/boxcli/shellenv.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616
type shellEnvCmdFlags struct {
1717
envFlag
1818
config configFlags
19-
runInitHook bool
2019
install bool
21-
pure bool
20+
noRefreshAlias bool
2221
preservePathStack bool
22+
pure bool
23+
runInitHook bool
2324
}
2425

2526
func shellEnvCmd(recomputeEnvIfNeeded *bool) *cobra.Command {
@@ -54,6 +55,11 @@ func shellEnvCmd(recomputeEnvIfNeeded *bool) *cobra.Command {
5455
"Preserves existing PATH order if this project's environment is already in PATH. "+
5556
"Useful if you want to avoid overshadowing another devbox project that is already active")
5657
_ = command.Flags().MarkHidden("preserve-path-stack")
58+
command.Flags().BoolVar(
59+
&flags.noRefreshAlias, "no-refresh-alias", false,
60+
"By default, devbox will add refresh alias to the environment"+
61+
"Use this flag to disable this behavior.")
62+
_ = command.Flags().MarkHidden("no-refresh-alias")
5763

5864
flags.config.register(command)
5965
flags.envFlag.register(command)
@@ -89,6 +95,7 @@ func shellEnvFunc(
8995

9096
envStr, err := box.NixEnv(cmd.Context(), devopt.NixEnvOpts{
9197
DontRecomputeEnvironment: !recomputeEnvIfNeeded,
98+
NoRefreshAlias: flags.noRefreshAlias,
9299
RunHooks: flags.runInitHook,
93100
})
94101
if err != nil {

internal/impl/devbox.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ func (d *Devbox) NixEnv(ctx context.Context, opts devopt.NixEnvOpts) (string, er
301301
envStr = fmt.Sprintf("%s\n%s;\n", envStr, hooksStr)
302302
}
303303

304-
envStr += "\n" + d.refreshAlias()
304+
if !opts.NoRefreshAlias {
305+
envStr += "\n" + d.refreshAlias()
306+
}
305307

306308
return envStr, nil
307309
}

internal/impl/devopt/devboxopts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ type UpdateOpts struct {
4545

4646
type NixEnvOpts struct {
4747
DontRecomputeEnvironment bool
48+
NoRefreshAlias bool
4849
RunHooks bool
4950
}

internal/impl/generate/tmpl/envrcContent.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use_devbox() {
22
watch_file devbox.json
3-
eval "$(devbox shellenv --init-hook --install{{ if .EnvFlag }} {{ .EnvFlag }}{{ end }})"
3+
eval "$(devbox shellenv --init-hook --install --no-refresh-alias{{ if .EnvFlag }} {{ .EnvFlag }}{{ end }})"
44
}
55
use devbox
66
{{ if .EnvFile }}

0 commit comments

Comments
 (0)