Skip to content

[Question]: Comparing the symbolic link solution with the environment variable solution #141

Closed

Description

@jan-bar

方案参考:https://github.com/Schniz/fnm

如下图所示,只需要在打开终端时设置一次环境变量。其中有个临时目录设置到环境变量PATH中。

image

实际上设置到PATH中的值也只是个目录软链接,重点就是后续切换环境,只需要修改该软连接的目标目录,轻松实现版本切换

image

上图是指向 alias 别名为 default 的版本,下图是直接指向固定版本的情况。这种方案允许为指定版本创建别名,使用时也可以不用记住指定版本,记住别名也能轻松切换版本。这种方案我感觉很灵活。

image

当前vfox的版本切换我看了,每次切换版本都需要设置PATH环境变量。我也是window的cmder用户,同样遇到 #129 的困扰。但我在用fnm时没遇到该问题(fnm支持cmd.exe且也有cmder设置教程),所以是否可以将vfox切换版本的方案改成fnm那种呢?

Activity

  1. added
    enhancement
    on Mar 23, 2024
  2. jan-bar commented on Mar 23, 2024

    @jan-bar
    ContributorAuthor

    fnm没有使用终端的hook功能,切换版本时仅仅修改目录链接目标地址,方法简单速度快。

  3. aooohan commented on Mar 25, 2024

    @aooohan
    Member

    首先, 非常感谢如此详细的说明.

    我在之前的#84 (comment), 提到过这个问题.

    简单来说, 对于Nodejs, 这种方案是没有任何问题的, 但是对于vfox作为一个通用SDK版本管理器而言,不能保证其他SDK不需要设置除了PATH之外的环境变量. 举个例子如JDK, 可能就需要配置JAVA_HOME. 因为有些中间件会默认查找当前环境变量来定位JDK的位置.

    当前, 这个issue暂时不打算关闭. 有些功能未来还是可以借鉴的.

  4. jan-bar commented on Mar 25, 2024

    @jan-bar
    ContributorAuthor

    @aooohan 切换时需要设置额外环境变量确实需要终端的hook功能。不过习惯win下cmd使用 clink方案的用户也有很多,比如我使用cmderr。我前两天尝试编写lua脚本实现hook,遇到一些问题,例如lua执行cmd命令的io.popen不会将环境变量传递给子进程,导致vfox env -s xxx不能正确输出。我觉得可以试试在这个 #129 议题中增强cmd终端的支持额。

  5. jan-bar commented on Mar 25, 2024

    @jan-bar
    ContributorAuthor

    我想起在使用过程中遇到一个问题,我在vfox挂载指令后面继续设置PATH。

    eval "$(vfox activate bash)"
    export PATH=$HOME/bin:$PATH

    结果就是vfox切换版本读取__VFOX_ORIG_PATH环境变量是我设置PATH之前的值,这时$HOME/bin在PATH环境变量中被丢掉了。

    如果将方案改为最开始设置临时目录,然后使用软连接切换版本就不会出现这种问题。

    目前我不得不将eval "$(vfox activate bash)"放到最后设置PATH指令后面执行。

  6. aooohan commented on Mar 25, 2024

    @aooohan
    Member

    结果就是vfox切换版本读取__VFOX_ORIG_PATH环境变量是我设置PATH之前的值,这时$HOME/bin在PATH环境变量中被丢掉了。

    上周Discord上也有用户反馈过. 下个版本修复吧.

  7. changed the title [-][Feature]: 可否换一种切换版本的方案[/-] [+][Question]: Comparing the symbolic link solution with the environment variable solution[/+] on Mar 25, 2024
  8. added
    question
    and removed
    enhancement
    on Mar 25, 2024
  9. locked and limited conversation to collaborators on Apr 10, 2024
  10. converted this issue into a discussionon Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions