Skip to content

Commit

Permalink
feat: Elvish Shell support
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahr committed Oct 8, 2021
1 parent 847ec73 commit 1af3e99
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 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
}
}
6 changes: 6 additions & 0 deletions lib/commands/command-export-shell-version.bash
Expand Up @@ -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"
;;
Expand All @@ -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"
;;
Expand Down
12 changes: 12 additions & 0 deletions test/version_commands.bats
Expand Up @@ -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 ]
Expand All @@ -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"
Expand Down

0 comments on commit 1af3e99

Please sign in to comment.