跳转到主内容

自定义

非官方测试版翻译

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

标准初始化会设置 Oh My Posh 默认的内置主题。

要设置新配置或主题,您需要修改 profile.<shell>rc 脚本中 oh-my-posh init <shell> 命令的 --config 选项(详见提示)。

--config 参数支持以下三种取值方式:

  • 本地配置文件路径

    --config 'C:/Users/Posh/myconfig.omp.json'
  • 主题名称(不带扩展名)

    --config 'jandedobbeleer'
  • 指向远程配置的 URL

    --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/jandedobbeleer.omp.json'
信息

使用主题名称(如 jandedobbeleer)或远程 URL 需要设备处于联网状态,系统会在 shell 启动时下载配置。虽然已内置缓存机制,但为获得最佳性能,建议使用本地配置文件。

设置配置

以下示例使用了 jandedobbeleer 主题的本地路径,请根据您的配置文件位置(本地或远程)调整 --config 参数的值。

Adjust the Oh My Posh init line in your $PROFILE by adding the --config flag with the location of your configuration.

oh-my-posh init pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression

Once altered, reload your profile for the changes to take effect.

. $PROFILE
信息

When the above command gives an error, make sure to create the profile first and add the oh-my-posh init above.

New-Item -Path $PROFILE -Type File -Force

In this scenario, it can also be that PowerShell blocks running local scripts. To solve that, set PowerShell to only require remote scripts to be signed using Set-ExecutionPolicy RemoteSigned, or sign the profile.

wsl

在 Windows 和 WSL 中使用 oh-my-posh 时,您可以通过指向 Windows 用户主目录中的主题来与 WSL 共享主题

在 WSL 中,可通过以下路径访问 Windows 用户主目录:/mnt/c/Users/<WINDOWSUSERNAME>

自定义配置

您可能喜欢某个主题但不喜欢其配色,或者想调整/添加某个组件(segment),又或是替换某些图标。无论何种情况,请先阅读可用选项,建议从配置部分开始。

您可以将当前主题(默认主题或通过 --config 设置的主题)导出为喜欢的格式(jsonyamltoml),用于调整并保存为自定义配置。

oh-my-posh config export --config jandedobbeleer --output ~/.mytheme.omp.json

实时重载

出于性能考虑,配置信息默认会被缓存。若您修改了配置文件后希望在不重启 shell 的情况下实时更新提示符,可使用以下命令启用实时重载功能。

oh-my-posh enable reload

您可通过以下命令禁用实时重载:

oh-my-posh disable reload

预览更改

如需预览修改效果,可使用以下命令渲染所有配置的提示符:

oh-my-posh print preview

若需强制渲染所有组件(无论当前上下文如何),请使用 --force 标志。

oh-my-posh print preview --force

阅读文档

要深入掌握主题定制方法,请详细阅读配置和组件部分的文档。配置部分涵盖 Oh My Posh 主题的核心结构和概念,而组件部分则详解每个可用组件的配置方法。