Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bash-env-json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ function capture() {
local -n _capture_env="$1"
local -n _capture_shellvars="$2"
local _name _value
# some shell variables leak into our environment, so inhibit that:
local -A _inhibit_shellvars=([_value]=X [BASH_LINENO]=X [COLUMNS]=X [LINES]=X)
# inhibit env vars which are side-effects of cd
local -A _inhibit_envvars=([PWD]=X [OLDPWD]=X)
# some shell variables leak into our environment, so inhibit those, along with side-effects of cd
local -A _inhibit_shellvars=([_value]=X [BASH_LINENO]=X [COLUMNS]=X [LINES]=X [DIRSTACK]=X)

# environment variables
while IFS='=' read -r -d '' _name _value; do
_capture_env["$_name"]="${_value}"
if test ! "${_inhibit_envvars[$_name]+EXISTS}"; then
_capture_env["$_name"]="${_value}"
fi
done < <(_env -0)

# shellvars
Expand All @@ -54,7 +58,7 @@ function capture() {
set | _sed -n -e '/^[a-zA-Z_][a-zA-Z_0-9]*=/s/=.*$//p'
set +o posix
); do
if test -v "$_name" -a ! "${_capture_env[$_name]+EXISTS}" -a ! "${_inhibit_shellvars[$_name]+EXISTS}"; then
if test -v "$_name" -a ! "${_capture_env[$_name]+EXISTS}" -a ! "${_inhibit_envvars[$_name]+EXISTS}" -a ! "${_inhibit_shellvars[$_name]+EXISTS}"; then
_capture_shellvars["$_name"]="${!_name}"
fi
done
Expand Down
4 changes: 4 additions & 0 deletions tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ function test_case() {
@test "shell-function-error" {
test_case shell-function-error --shellfns f
}

@test "cd-does-nothing" {
test_case cd-does-nothing
}
1 change: 1 addition & 0 deletions tests/cd-does-nothing.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cd ${TMPDIR:-/tmp}
4 changes: 4 additions & 0 deletions tests/cd-does-nothing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"env": {},
"shellvars": {}
}
Empty file added tests/cd-does-nothing.setup.env
Empty file.
Loading