Skip to content

feat: support tfenv use - to switch to previous version (#378) - #483

Merged
Zordrak merged 1 commit into
masterfrom
feat/378-use-dash
Apr 24, 2026
Merged

Zordrak merged 1 commit into
masterfrom
feat/378-use-dash

Conversation

@Zordrak

@Zordrak Zordrak commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Similar to cd -, tfenv use - now switches back to the previously active default version:

$ tfenv use 1.5.0
Switching default version to v1.5.0
$ tfenv use 1.6.0
Switching default version to v1.6.0
$ tfenv use -
Switching to previous version: 1.5.0
Switching default version to v1.5.0
$ tfenv use -
Switching to previous version: 1.6.0
Switching default version to v1.6.0

Implementation: Before writing the new version to $TFENV_CONFIG_DIR/version, the current version is saved to version.prev (only when the version actually changes). When - is passed as the argument, the previous version is read from version.prev and used as the requested version.

Changes:

  • libexec/tfenv-use: Handle - arg to read from version.prev; save current version before overwriting.
  • lib/helpers.sh: Add version.prev cleanup to cleanup() to prevent test pollution.
  • test/test_use_dash.sh: New test file with two cases — toggling between versions and error on no previous version.

Fixes #378

Similar to cd -, tfenv use - now switches back to the previously
active default version. The previous version is saved to
\$TFENV_CONFIG_DIR/version.prev each time tfenv use writes a new
default. Running tfenv use - again toggles between the two versions.

If no previous version exists, the command errors with a clear
message.

Also adds version.prev cleanup to the cleanup() helper in
lib/helpers.sh to prevent test pollution.

Fixes #378
@Zordrak
Zordrak merged commit a834f86 into master Apr 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tfenv shortcut for quickly switching to the last used version

1 participant