Skip to content

Commit

Permalink
fix: adjust .tool-versions behavior
Browse files Browse the repository at this point in the history
The current vfox strategy is that if we have a .tool-version in the project (project/.tool-versions), that version will be used in the current shell, regardless of whether you switch directories or not, the version is not changed until the next .tool-versions file is encountered, or vfox use command is executed manually.

fix #228
  • Loading branch information
aooohan committed Apr 29, 2024
1 parent 01fa25d commit f5c2184
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,25 @@ func aggregateEnvKeys(manager *internal.Manager) (*env.Envs, error) {
}); err != nil {
return nil, err
}
tvs, err := toolset.NewMultiToolVersions([]string{
manager.PathMeta.CurTmpPath,
manager.PathMeta.HomePath,
})

curToolVersion, err := toolset.NewToolVersion(manager.PathMeta.CurTmpPath)
if err != nil {
return nil, err
}
// If we encounter a .tool-versions file, it is valid for the entire shell session,
// unless we encounter the next .tool-versions file or manually switch to the use command.
for k, v := range workToolVersion.Record {
curToolVersion.Record[k] = v
}
_ = curToolVersion.Save()

homeToolVersion, err := toolset.NewToolVersion(manager.PathMeta.HomePath)
if err != nil {
return nil, err
}

// Add the working directory to the first
tvs = append(toolset.MultiToolVersions{workToolVersion}, tvs...)
tvs := append(toolset.MultiToolVersions{}, workToolVersion, curToolVersion, homeToolVersion)

return manager.EnvKeys(tvs)
}

0 comments on commit f5c2184

Please sign in to comment.