From 1af3e99c63c5b0dc2b493417526de847f1d91361 Mon Sep 17 00:00:00 2001 From: Elijah Shaw-Rutschman Date: Thu, 7 Oct 2021 22:41:51 -0500 Subject: [PATCH] feat: Elvish Shell support --- lib/asdf.elv | 34 +++++++++++++++++++ .../command-export-shell-version.bash | 6 ++++ test/version_commands.bats | 12 +++++++ 3 files changed, 52 insertions(+) create mode 100644 lib/asdf.elv diff --git a/lib/asdf.elv b/lib/asdf.elv new file mode 100644 index 000000000..05b230fa7 --- /dev/null +++ b/lib/asdf.elv @@ -0,0 +1,34 @@ +use path + +asdf_dir = (path:dir (src)[name]) +put $asdf_dir +set-env ASDF_DIR $asdf_dir + +var asdf_user_shims +if (and (has-env "ASDF_DATA_DIR") (not (== $E:ASDF_DATA_DIR ""))) { + asdf_user_shims = $E:ASDF_DATA_DIR/shims +} else { + asdf_user_shims = $asdf_dir/shims +} + +# Add asdf to PATH +for path [ + $asdf_dir/bin + $asdf_user_shims +] { + if (not (has-value $paths $path)) { + paths = [$path $@paths] + put $paths + } +} + +# Add function wrapper so we can export variables +fn asdf [command @args]{ + if (== $command "shell") { + # source commands that need to export variables + eval (slurp <(asdf export-shell-version elvish $@args)) + } else { + # forward other commands to asdf script + command asdf $command $@args + } +} diff --git a/lib/commands/command-export-shell-version.bash b/lib/commands/command-export-shell-version.bash index 6e3fa371d..8524b5a05 100644 --- a/lib/commands/command-export-shell-version.bash +++ b/lib/commands/command-export-shell-version.bash @@ -23,6 +23,9 @@ shell_command() { fish) printf "set -e %s\\n" "$version_env_var" ;; + elvish) + echo "unset-env $version_env_var" + ;; *) printf "unset %s\\n" "$version_env_var" ;; @@ -42,6 +45,9 @@ shell_command() { fish) printf "set -gx %s \"%s\"\\n" "$version_env_var" "$version" ;; + elvish) + echo "set-env $version_env_var \"$version\"" + ;; *) printf "export %s=\"%s\"\\n" "$version_env_var" "$version" ;; diff --git a/test/version_commands.bats b/test/version_commands.bats index 35fcb7a3a..8d36425af 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -371,6 +371,12 @@ false" [ "$output" = "set -gx ASDF_DUMMY_VERSION \"1.1.0\"" ] } +@test "export-shell-version should use set-env when shell is elvish" { + run asdf export-shell-version elvish "dummy" "1.1.0" + [ "$status" -eq 0 ] + [ "$output" = "set-env ASDF_DUMMY_VERSION \"1.1.0\"" ] +} + @test "export-shell-version should unset when --unset flag is passed" { run asdf export-shell-version sh "dummy" "--unset" [ "$status" -eq 0 ] @@ -383,6 +389,12 @@ false" [ "$output" = "set -e ASDF_DUMMY_VERSION" ] } +@test "export-shell-version should use unset-env when --unset flag is passed and shell is elvish" { + run asdf export-shell-version elvish "dummy" "--unset" + [ "$status" -eq 0 ] + [ "$output" = "unset-env ASDF_DUMMY_VERSION" ] +} + @test "[shell - dummy_plugin] wrapper function should support latest" { . $(dirname "$BATS_TEST_DIRNAME")/asdf.sh asdf shell "dummy" "latest"