asdf
asdf copied to clipboard
Display configured tool versions from the closest (project) directory only
Is your feature request related to a problem? Please describe
I work with projects that have different combinations and versions of dependencies. It would be useful to display, for example in a shell prompt, which tools are configured for the current project directory.
~projects/widget-corp [ ruby 2.7.8 nodejs 14.5.2 elm 0.19.2 ]
$
asdf has access to that information, but doesn't make it possible to separate out the "project" configuration from any configuration inherited from ancestor directories.
Describe the proposed solution
There would be some mechanism that acts similar to asdf current but with the following heuristic:
- Starting in the current directory,
asdfwould check to see if a version file is present, either:- a
.tool-versionsfile, or - if
legacy_version_fileis enabled, any legacy version file supported by an enabled plugin
- a
- If none are present,
asdfwould iterate up the file tree towards/looking for any directory with at least one supported version file - As soon as
asdfreaches any directory with at least one version file, it stops, and outputs the versions defined by all supported version files in that directory.
As an example, this mechanism might be exposed as a separate command, asdf closest or as a variant of an existing command asdf current --closest
Describe similar asdf features and why they are not sufficient
asdf current outputs a similar set of data using a similar heuristic to the one suggested. However, asdf current iterates up the directory tree separately for each enabled plugin. That means that any plugin not explicitly configured in a current project directory would be displayed if it was configured at the global level.
The intention of the suggested command is to explicitly exclude parent or global configuration.
Describe other workarounds you've considered
The following command will process the output of asdf current ignoring any versions that are globally unconfigured, currently uninstalled or set to the value system.
asdf current 2> /dev/null | awk '{ if ($2 != "system") print $1 ":" $2 }'
However this doesn't allow me to filter just to versions configured in the project directory, it's possible for versions to leak in from parent directories.
Does my comment here help at all? https://github.com/asdf-vm/asdf/issues/1002#issuecomment-884197641
Given the output of asdf current it shouldn't be too hard to find the version file closest to $(pwd).