diff options
| author | mo khan <mo.khan@gmail.com> | 2020-06-05 15:00:03 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-06-05 15:00:03 -0600 |
| commit | ba39248964aa718cca14c82bb621d4703c9e1638 (patch) | |
| tree | d2386b46e7b0efe37b255714b5222c3f35afd7b2 | |
| parent | 5d7201bf7830f16174adda1cd145e6804d7056b4 (diff) | |
Extract function to switch to exact tool and version
| -rw-r--r-- | config/.bashrc | 15 | ||||
| -rwxr-xr-x | run.sh | 5 |
2 files changed, 13 insertions, 7 deletions
diff --git a/config/.bashrc b/config/.bashrc index 9c4dd9a..5ab592a 100644 --- a/config/.bashrc +++ b/config/.bashrc @@ -20,16 +20,23 @@ update_java_home() { fi } +function switch_to_exact() { + local tool=$1 + local version=$2 + + asdf shell "$tool" "$version" + if [[ "$tool" = "java" ]]; then + update_java_home + fi +} + function switch_to() { local tool=$1 local major_version=$2 local version version="$(grep "$tool" "$HOME/.tool-versions"| tr ' ' '\n' | grep "^$major_version")" - asdf shell "$tool" "$version" - if [[ "$tool" = "java" ]]; then - update_java_home - fi + switch_to_exact "$tool" "$version" } function major_version_from() { @@ -87,8 +87,7 @@ function prepare_project() { if [ -n "$LM_JAVA_VERSION" ]; then switch_to java "adopt-openjdk-${LM_JAVA_VERSION}" elif [ -n "$ASDF_JAVA_VERSION" ]; then - asdf shell java "$ASDF_JAVA_VERSION" - update_java_home + switch_to_exact java "$ASDF_JAVA_VERSION" else switch_to java "adopt-openjdk-8" fi @@ -96,7 +95,7 @@ fi if [ -n "$LM_PYTHON_VERSION" ]; then switch_to python "$(major_version_from "$LM_PYTHON_VERSION")" elif [ -n "$ASDF_PYTHON_VERSION" ]; then - asdf shell python "$ASDF_PYTHON_VERSION" + switch_to_exact python "$ASDF_PYTHON_VERSION" else switch_to python "3" fi |
