1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
diff --git a/internal/cmd/const.go b/internal/cmd/const.go
index 8798174..52687ca 100644
--- a/internal/cmd/const.go
+++ b/internal/cmd/const.go
@@ -7,6 +7,7 @@ const (
DIRENV_DEBUG = "DIRENV_DEBUG"
DIRENV_DISABLE = "DIRENV_DISABLE"
+ DIRENV_WORKDIR = "DIRENV_WORKDIR"
DIRENV_DIR = "DIRENV_DIR"
DIRENV_FILE = "DIRENV_FILE"
DIRENV_WATCHES = "DIRENV_WATCHES"
diff --git a/internal/cmd/env_diff.go b/internal/cmd/env_diff.go
index 58f7dde..4fde9c5 100644
--- a/internal/cmd/env_diff.go
+++ b/internal/cmd/env_diff.go
@@ -14,6 +14,7 @@ var IgnoredKeys = map[string]bool{
"DIRENV_BASH": true,
// should only be available inside of the .envrc or .env
+ "DIRENV_WORKDIR": true,
"DIRENV_IN_ENVRC": true,
"COMP_WORDBREAKS": true, // Avoids segfaults in bash
diff --git a/internal/cmd/env_diff_test.go b/internal/cmd/env_diff_test.go
index 9050d97..a889094 100644
--- a/internal/cmd/env_diff_test.go
+++ b/internal/cmd/env_diff_test.go
@@ -41,6 +41,9 @@ func TestIgnoredEnv(t *testing.T) {
if !IgnoredEnv(DIRENV_BASH) {
t.Fail()
}
+ if !IgnoredEnv(DIRENV_WORKDIR) {
+ t.Fail()
+ }
if IgnoredEnv(DIRENV_DIFF) {
t.Fail()
}
diff --git a/internal/cmd/rc.go b/internal/cmd/rc.go
index 8ea8c7e..ad0f2dc 100644
--- a/internal/cmd/rc.go
+++ b/internal/cmd/rc.go
@@ -211,6 +211,7 @@ func (rc *RC) Load(previousEnv Env) (newEnv Env, err error) {
wd := config.WorkDir
direnv := config.SelfPath
newEnv = previousEnv.Copy()
+ newEnv[DIRENV_WORKDIR] = wd
newEnv[DIRENV_WATCHES] = rc.times.Marshal()
defer func() {
// Record directory changes even if load is disallowed or fails
diff --git a/test/direnv-test-common.sh b/test/direnv-test-common.sh
index e6c5ad0..edc368c 100755
--- a/test/direnv-test-common.sh
+++ b/test/direnv-test-common.sh
@@ -228,6 +228,13 @@ test_start "in-envrc"
test_eq "$es" "1"
test_stop
+test_start "workdir"
+ cd child
+ direnv_eval
+ test_eq "$ENVRC_PWD" "$TEST_DIR/scenarios/workdir"
+ test_eq "$WORKDIR_FROM_DIRENV" "$TEST_DIR/scenarios/workdir/child"
+test_stop
+
test_start "missing-file-source-env"
direnv_eval
test_stop
diff --git a/test/scenarios/workdir/.envrc b/test/scenarios/workdir/.envrc
new file mode 100644
index 0000000..08384d3
--- /dev/null
+++ b/test/scenarios/workdir/.envrc
@@ -0,0 +1,2 @@
+export ENVRC_PWD=$PWD
+export WORKDIR_FROM_DIRENV=$DIRENV_WORKDIR
diff --git a/test/scenarios/workdir/child/.keep b/test/scenarios/workdir/child/.keep
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/test/scenarios/workdir/child/.keep
@@ -0,0 +1 @@
+
|