Skip to content

Commit 75bd04a

Browse files
authored
Merge pull request asdf-vm#560 from asdf-vm/tb/env-path-fix
with_plugin_env PATH fix
2 parents 16e8d34 + 20522bb commit 75bd04a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/utils.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,12 @@ with_plugin_env() {
499499
plugin_path=$(get_plugin_path "$plugin_name")
500500

501501
# add the plugin listed exec paths to PATH
502-
local path
503-
path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH"
502+
local path exec_paths
503+
exec_paths="$(list_plugin_exec_paths "$plugin_name" "$full_version")"
504+
505+
# exec_paths contains a trailing newline which is converted to a colon, so no
506+
# colon is needed between the subshell and the PATH variable in this string
507+
path="$(echo "$exec_paths" | tr '\n' ':')$PATH"
504508

505509
# If no custom exec-env transform, just execute callback
506510
if [ ! -f "${plugin_path}/bin/exec-env" ]; then

test/shim_env_command.bats

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,19 @@ teardown() {
6666
[ "$output" == "$ASDF_DIR/shims/dummy" ]
6767
[ "$status" -eq 0 ]
6868
}
69+
70+
@test "asdf env should set PATH correctly" {
71+
echo "dummy 1.0" > $PROJECT_DIR/.tool-versions
72+
run asdf install
73+
74+
run asdf env dummy
75+
[ "$status" -eq 0 ]
76+
77+
# Should set path
78+
path_line=$(echo "$output" | grep '^PATH=')
79+
[ "$path_line" != "" ]
80+
81+
# Should not contain duplicate colon
82+
run grep '::' <(echo "$path_line")
83+
[ "$duplicate_colon" == "" ]
84+
}

0 commit comments

Comments
 (0)