Suppress Trailing Comma Warning for JSONC file in VSCode
VSCode 在 JSONC 文件中会对 尾随逗号 jsonc(519) 产生警告,很明显是非期望的,否则失去了这个语言的特性。
VSCode 侧非常不愿意修改默认行为或者开放配置,觉得在 Schema 没有明确指定的情况下就该产生警告。
好吧那就自定义个 Schema ,Tolerate trailing commas in jsonc format · 议题 #102061 · microsoft/vscode
"json.schemas": [
{
// https://github.com/microsoft/vscode/issues/102061#issuecomment-657080963
"fileMatch": [ "*.jsonc", "bun.lock" ],
"schema": {
"allowTrailingCommas": true
}
}
],本地编译使用 goreleaser 的项目
goreleaser build --snapshot --single-target --clean有的软件通过在 hook 中绑定 Windows 可执行文件的图标,注意就不要 --skip=post-hooks --skip=before 了
但如果遇到还未适配 v2 的,需要下载 v1.26 的 goreleaser
goreleaser_v1 check
goreleaser_v1 build --snapshot --single-target --cleanvfox 执意要修改我的 PATH
我因为性能问题,没有 挂载 vfox 到 Shell 上,这样会造成 vfox use golang@1.24.2 时强制修改我的环境变量,给 PATH 添加几个目录。
Warning: The current shell lacks hook support or configuration. It has switched to global scope automatically
https://vfox.dev/guides/faq.html#switch-xxx-not-work-or-the-vfox-use-command-does-not-work
本来使用 vfox 就是为了减少 PATH 列表的尺寸的,这样明显不符合预期。
直接改代码去掉逻辑。do not touch my PATH · version-fox/vfox@eaedca4
golang 启动会寻找 gcc
处理 version-fox shim 会叠加一层耗时 时发现 golang 会扫描 PATH 寻找 gcc,花费了上百毫秒,光输出个 version 就等待好久。
代码对应这里 go/src/cmd/go/internal/cfg/cfg.go at 9b2d39b75bcc8ced3eaab1c841d7d62e27867931 · golang/go,而它的条件 ctxt.CgoEnabled 又是在 go/src/go/build/build.go at 9b2d39b75bcc8ced3eaab1c841d7d62e27867931 · golang/go 设置上的
日常编译不需要 cgo,等有必要了用 docker 编译才是正道。
配置一下全局禁用 cgo,加速启动
$env:CGO_ENABLED="0"
然而还有一个查找 gccgo 的流程,go/src/cmd/go/internal/work/gccgo.go at 9b2d39b75bcc8ced3eaab1c841d7d62e27867931 · golang/go 这个就没办法绕过了,除非自己编译 go
func init() {
GccgoName = cfg.Getenv("GCCGO")
if GccgoName == "" {
GccgoName = "gccgo"
}
if GccgoName != "gccgo" {
GccgoChanged = true
}
GccgoBin, gccgoErr = pathcache.LookPath(GccgoName)
}
func checkGccgoBin() {
GccgoBin, gccgoErr = pathcache.LookPath(GccgoName)
if gccgoErr == nil {
return
}
fmt.Fprintf(os.Stderr, "cmd/go: gccgo: %s\n", gccgoErr)
base.SetExitStatus(2)
base.Exit()
}$ $env:CGO_ENABLED=0
$ hyperfine '.\golang-1.25.1\bin\go.exe version' 'C:\msys64\ucrt64\lib\go\bin\go.exe version' "C:\Users\enihsyou\.version-fox\cache\golang\v-1.25.1\golang-1.25.1\bin\go.exe version"
Benchmark 1: .\golang-1.25.1\bin\go.exe version
Time (mean ± σ): 10.5 ms ± 3.8 ms [User: 4.7 ms, System: 5.5 ms]
Range (min … max): 7.0 ms … 53.1 ms 167 runs
Benchmark 2: C:\Users\enihsyou\.version-fox\shims\go.exe version
Time (mean ± σ): 29.8 ms ± 1.8 ms [User: 13.5 ms, System: 13.8 ms]
Range (min … max): 27.1 ms … 35.8 ms 72 runs
Benchmark 4: C:\Users\enihsyou\.version-fox\cache\golang\v-1.25.1\golang-1.25.1\bin\go.exe version
Time (mean ± σ): 16.2 ms ± 1.3 ms [User: 6.4 ms, System: 9.2 ms]
Range (min … max): 14.4 ms … 21.3 ms 112 runs
Summary
.\golang-1.25.1\bin\go.exe version ran
1.54 ± 0.56 times faster than C:\Users\enihsyou\.version-fox\cache\golang\v-1.25.1\golang-1.25.1\bin\go.exe version
2.83 ± 1.02 times faster than C:\Users\enihsyou\.version-fox\shims\go.exe version耗时上,移除 CGO < 原版 < shim,去掉两个 LookPath 就能在 shim 上为 prompt 节约 13ms;如果愿意把 shim 换成软链接,再配置 GOROOT 能节约 20ms
oh-my-posh 可执行文件路径缓存
不知为何 oh-my-posh 虽然定义了 cmdCache,但只在当前进程生效。一个耗费数毫秒的动作,每次生成 prompt 都要重新计算一遍不太行。虽然我知道有环境切换工具等,它们会随时改变 PATH,但在我这里没这回事,基本固定。
https://github.com/JanDeDobbeleer/oh-my-posh/commit/e4d7fb6167a45c377a16363bd869345e6d2bb6ac
oh-my-posh v26 应用极致性能补丁
v26 和 v25 不一样的地方是内部生成 POSH_SESSION_ID,自己的配置文件因为不匹配 SessionID 不再生效。解决方案是直接改生成器
https://github.com/JanDeDobbeleer/oh-my-posh/commit/0fdb9c34cf20c374d98d95a45e98b0e3cb676a0e
Bash PATH 中有 /usr/games
在 WSL2 中,我不希望看到 PATH 中有没意义的目录,确认是在 /etc/environment 定义的,改改。
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"不得不说,Linux 生态真是有太多 ” 实践 ” 了,每个发行版有自己的一套习惯
注意,修改此文件需要重新 login 才能生效