跳转到主内容

快速入门

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

获取源代码

源代码托管于 GitHub。若需贡献代码,请先创建 fork,这样您就可以在自己的仓库中进行修改,然后在 Oh My Posh 官方仓库创建拉取请求。

要在本地克隆您的 Oh My Posh 分支,请打开终端并将 <user> 替换为您的 GitHub 用户名。

git clone git@github.com:<user>/oh-my-posh.git

安装依赖

go

The codebase is in go, meaning we need a working go setup before we can do anything else. Have a look at the go guide to get up and running with go in no time!

注意

Oh My Posh needs at least go 1.25.5

golangci-lint

To make sure we keep on writing quality code, golang-ci lint is used to validate the changes. Have a look at the local installation guide to make sure you can validate this yourself as well.

nodejs

The documentation is written in markdown and uses Docusaurus to generate the website. To validate your changes, you'll need to have nodejs installed so you can run the website locally.

Visual Studio Code

If you're not using Visual Studio Code yet, it's a great editor to work with go and the project has the configuration built-in. You can download it here.

配置 Visual Studio Code

仓库中提供了 Visual Studio Code 的默认配置(.vscode 文件夹):

  • 默认配置的 linter 工具是 golangci-lint

  • 提供推荐扩展以实现平滑引导

  • 提供默认的运行和调试配置

安装扩展后:

  • 按 F5 即可启动调试

  • 可通过测试资源管理器运行所有测试

运行测试

Go 源代码位于 src/ 目录,请确保进入该目录后再继续操作。

单元测试

go test -v ./...

golangci-lint

golangci-lint run

构建应用

验证修改最简便的方式是编写测试。但由于这是可视化工具,您还需要在 shell 中运行提示符来确认变更效果。

如果 Oh My Posh 已在您的 PATH 中,您需要将其作为输出参数使用,或确保 $GOPATH/bin/ 目录在 PATH 中优先于 Oh My Posh 二进制文件。

go build -o (Get-Command oh-my-posh.exe).Source

或者:

$env:PATH = "$env:GOPATH\bin;$env:PATH"
go build -o $GOPATH/bin/oh-my-posh

本地运行网站

打开终端进入仓库的 website 文件夹,安装依赖后启动网站:

npm install
npm start

这将启动本地服务器 http://localhost:3000,您可以在此查看变更效果。

补充建议

在 VS Code 中配置 Delve

Delve 配置默认较为严格(特别是字符串长度限制)。您可以在 VS Code(settings.json 或直接修改 launch.json)中放宽部分限制:

"go.delveConfig": {

"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 3,
"maxStringLen": 400,
"maxArrayValues": 400,
"maxStructFields": -1
},
"apiVersion": 2,
"showGlobalVariables": false
}

下一步

环境配置完成后,您就可以开始修改代码并提交首个 PR 了!