asdf-vm / asdf-vm/asdf

Display configured tool versions from the closest (project) directory only

Open
#1,004 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
25.6k
Forks
941
Avg merge
9h 24m
Merged PRs (30d)
3

Description

### 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, `asdf` would check to see if a version file is present, either:
* a `.tool-versions` file, or
* if `legacy_version_file` is enabled, any legacy version file supported by an enabled plugin
* If none are present, `asdf` would iterate up the file tree towards `/` looking for any directory with at least one supported version file
* As soon as `asdf` reaches 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.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing `asdf current` command and its per-plugin directory traversal, then trace how `.tool-versions` and legacy plugin version files are discovered. Done means a closest-directory command or option reports all supported versions from the first directory containing a version file and excludes inherited or global settings; add coverage for the stated traversal cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, shell
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.