asdf
asdf copied to clipboard
Search for other executable on PATH if no .tool-versions and no global
Is your feature request related to a problem? Please describe
In my scenario I have the tool terraform installed globally via Homebrew where I always get the latest version and completion automatically. Sometimes I need an older version of Terraform in that case I want to use asdf. I would like Asdf to look for another executable on PATH if no .tool-versions and no global version is available before erroring out.
Describe the proposed solution
Adjust asdf maybe via a flag to look for another fitting executable on PATH if no .tool-versions can be found and no global version has been set for a package.
if tool_version_file_somewhere; then
# continue as usual
elif global_version_set; then
# continue as usual
elif exe_in_path_other_than_asdf_shim; then
# call this exe with args
else
# print error "No version is set for command..."
fi
Describe similar asdf features and why they are not sufficient
Using the globals feature of Asdf is not sufficient in comparison to Homebrew. Homebrew handles automatic updates and completion.
Describe other workarounds you've considered
- Using asdf globals instead of Homebrew for packages I want to always keep up to date and globally available.
- Monkeypatch asdf. Could be possible if overall modification is feasible because I use Ansible to bootstrap my environments.
I think I already found a code modification that works for me! Thanks to asdf being implemented in Bash making adjustments is super easy to do.
What I have figured out so far is that the function with_shim_executable in lib/utils.bash is basically responsible for figuring out what exact executable to call.
Within this function there is an conditional that triggers the execution if a version has been selected / found. If such a version has not been found, the next block handles the error output. I simply added an else to the aforementioned conditional like in the following minimal example:
if [ -n "$selected_version" ]; then
# ...
else
"$shim_exec" "x" "x" "/home/linuxbrew/.linuxbrew/bin/shfmt"
return $?
fi
The only problem is that this does not support pre hooks which is fine for me because I don't need any hooks in that case anyway.
Here is the change applied to a fork: https://github.com/asdf-vm/asdf/compare/master...trallnag:asdf:fallback-path-exe
I have what I think is a similar problem. I have mysql installed via homebrew to get version 5.7 (the [email protected] brew) and I have asdf-mysql installed. I’d love to be able to clear the local asdf mysql version to allow the other version that homebrew has to work. My only solution that I have currently is to uninstall asdf-mysql.
You could try applying the patch linked in my previous comment
This functionality was intended to be covered by https://asdf-vm.com/manage/versions.html#fallback-to-system-version
I think there is an open issue somewhere because that feature is not quite behaving as expected, but you should give it a go nonetheless.
Edit:
Sorry, the above links do not properly explain, we should probably update the docs for this.
You can have more than one version defined for each tool:
python 3.10.6 system
I cannot remember if it checks left to right or right to left (another reasons we should update the docs), but asdf will look for one, then fallback to the next and so on. system is a special keyword to fall back outside of the asdf shims to another install resolved by your machine.
@jthegedus, this is exactly what I was looking for. Thanks for pointing out this already existing feature. Will give it a try in the next few days once I find the time.