You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature]: Support clink、cmder shell on Windows #129
local originalPath = os.getenv('PATH')
local cwd_prompt = clink.promptfilter(30)
function cwd_prompt:filter(prompt)
-- if os.isfile('.tool-versions') then
-- end
-- Run vfox command to get env vars.
local handle = io.popen("vfox env -s pwsh")
local result = handle:read("*a")
handle:close()
-- 去掉开头的部分
if string.len(result) > 0 then
result = string.gsub(result, "$env:PATH='", "")
result = string.gsub(result, "';", "")
print(result)
-- local currentPath = os.getenv('PATH')
-- os.setenv("PATH", result .. ";" .. currentPath)
end
end
Activity
aooohan commentedon Mar 20, 2024
因为cmd不支持hook所以会有提示语.
如果支持hook的话可以支持的, 参照下面的进行实现就可以:
https://github.com/version-fox/vfox/blob/main/internal/shell/powershell.go
https://github.com/version-fox/vfox/blob/main/internal/shell/shell.go
有兴趣可以提个PR ;)
[-][Feature]: 支持更多windows shell,比如clink、cmder[/-][+][Feature]: Support clink、cmder shell on Windows[/+]ViCrack commentedon Mar 21, 2024
验证过可以支持hook的,用lua脚本扩展
大体上hook脚本可以这么写,甚至clink还可以加上vfox命令自动完成 (https://github.com/vladimir-kotikov/clink-completions/blob/master/nvm.lua)
不过我不太清楚pwsh实现方式,为什么需要加载EnvContent,和最后进程退出的env --cleanup是在干什么
https://github.com/version-fox/vfox/blob/main/internal/shell/powershell.go
按我目前的理解设计是这样:
通过hook shell prompt,能够在shell每次进入目录时候执行命令vfox env命令,执行该命令之后拿到在当前目录下nodejs的真实路径,
然后获取当前最新的环境变量PATH,在开头拼接上nodejs的真实路径,然后设置shell的环境变量PATH即可
另外这里为了防止PATH无限的拼接到开头,或许可以加个(@vfoxstart@和@vfoxend@)等标识符,每次都先判断如果存在就去掉老的这部分,然后再拼接(不知道还有什么简单的方法)
至于那个env --cleanup好像没啥用,设置的PATH环境变量只会对当前进程有效,当shell退出后,不需要手动清理
aooohan commentedon Mar 21, 2024
EnvContent就是一个占位符, vfox会把知道需要配置的环境变量和PATH(初始的环境的和全局SDK的), 通过你实现的shell翻译成对应的语句(也就是Export函数的实现), 替换到EnvContent上.
清理临时文件, 因为
vfox use --session模式, 会产生临时文件, 这就需要shell退出的时候及时清理.不是每次进入目录, 而是每次执行完命令都需要调用
vfox env命令jan-bar commentedon Mar 27, 2024
jan-bar@7321390
我自己测试了这个改动,目前完成全局、会话、项目三种切换模式都没问题。没找到clink退出终端的hook,但是我看清理逻辑会删除一定时间之前的会话文件,应该没啥大问题。
按照readme描述在clink脚本目录添加2个脚本文件即可。也不知道有没有更好的方案,所以没提PR。
aooohan commentedon Mar 28, 2024
jan-bar commentedon Mar 28, 2024
不好意没有测试纯clink的场景,我习惯用cmder了,我的测试是在cmder里面成功。你可以下载cmder试试看。
https://github.com/cmderdev/cmder/releases
我刚用纯clink也出现相同问题,我再查查看怎么解决这个问题吧。
jan-bar commentedon Mar 28, 2024
我更新了方法,现在只需要在clink脚本路径放一个lua脚本就可以了。之前多了个
vfox.cmd脚本是因为cmder启动脚本会自动执行,而原生的clink不会自动执行,但会自动执行脚本目录下所有*.lua脚本。因此我把所有逻辑都写到lua里面,并且在clink和cmderr中都测试通过了。这是改动:jan-bar@f3d4a5d
aooohan commentedon Apr 1, 2024
这个放在下个版本处理.
jan-bar commentedon Apr 1, 2024
简单的写个自动补全脚本,如果需要
vfox use -s [email protected]带版本号的话需要解析vfox ls的结果,有点麻烦没有弄。不过直接用vfox use -s xxx会弹出选择界面,我觉得也足够了。不过我看最新仓库代码换了插件相关逻辑,到时候这个自动补全脚本还得优化额。。暂时我的 https://github.com/jan-bar/vfox/tree/feat_clink 这个分支代码我自己用起来还可以额。
aooohan commentedon Apr 1, 2024
@jan-bar 有兴趣加入VersionFox吗? 哈哈哈, clink玩的太6了.
jan-bar commentedon Apr 1, 2024
这都是看clink官方文档,然后再照着cmder写好的一些命令脚本改改额。其实我只用到clink的很小一部分功能额。
话说VersionFox咋加入?是 discord 这个么?我已经加入了额。。
aooohan commentedon Apr 1, 2024
不是Discord, 我给你发邮件, 注意看邮箱
jan-bar commentedon Apr 1, 2024
好的,已经加入了。
feat(add clink support): add clink to support window cmd terminal
jan-bar commentedon Apr 2, 2024
#167 我创建了clink的所有功能,包括自动补全和vfox环境切换。再测测看看有没有问题吧。这次加上了use带版本的自动补全。
aooohan commentedon Apr 2, 2024
太帅了! 我下午测试一下.
ViCrack commentedon Apr 2, 2024
666
jan-bar commentedon Apr 3, 2024
我提交了一些修改,
vfox use不用带-s/-g/-p参数去补全了,命令是支持直接vfox use [email protected]。而vfox env必须vfox env -s xxx才需要补全终端名称。感觉这个自动补全需要看体验去优化啊。aooohan commentedon Apr 3, 2024
不用一次就写得很完美, 开源项目嘛, 慢慢来!
试了, 非常棒!
jan-bar commentedon Apr 3, 2024
嗯嗯,感谢支持。那个lua脚本,我暂时也想不出有啥需要改的了。我已经按照自己的用法,比对每个命令的参数做好补全了额。
aooohan commentedon Apr 3, 2024
也感谢你的贡献!