--- tags: Oh-My-Posh Powershell --- # Powershell oh my posh 自訂主題 1. 透過以下命令可以找到 themes json 檔案所存放的路徑 ```powershell $ Get-PoshThemes -list ``` 可從返回的訊息找到檔案路徑 (Themes location): Themes location: C:\Users\<username>\AppData\Local\oh-my-posh\themes 2. 參考[官方的教學、範例主題](https://ohmyposh.dev/docs/customize)進行更改 3. 對當前畫面套用自定義主題的 json 檔案 (假設檔案路徑為 `MyPoshTheme.omp.json`) ```powershell oh-my-posh init pwsh --config MyPoshTheme.omp.json | Invoke-Expression ``` 4. 若要每次開啟 Powershell 都套用主題,就將 `MyPoshTheme.omp.json` 放入第一步驟找到的 `Themes location` 路徑之中,並於 $Profile 中指定使用 `MyPoshTheme` ```powershell notepad $Profile ``` 加入以下內容: ```notepad Import-Module posh-git Import-Module oh-my-posh Set-PoshPrompt -Theme MyPoshTheme ``` 5. 補充: 直接匯出指定主題 (`mytheme.omp.json`) 的設定檔案 ```powershell oh-my-posh config export --output ~/.mytheme.omp.json ``` 6. 分享一下我的設定: `MyPoshTheme.omp.json` ```json { "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", "blocks": [ { "alignment": "left", "segments": [ { "background": "#9A348E", "foreground": "#ffffff", "leading_diamond": "\ue0b6", "style": "diamond", "template": "{{ .UserName }} ", "type": "session" }, { "background": "#DA627D", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "properties": { "style": "folder" }, "style": "powerline", "template": " {{ .Path }} ", "type": "path" }, { "background": "#FCA17D", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "properties": { "branch_icon": "", "fetch_stash_count": true, "fetch_status": false, "fetch_upstream_icon": true }, "style": "powerline", "template": " \u279c ({{ .UpstreamIcon }}{{ .HEAD }}{{ if gt .StashCount 0 }} \uf692 {{ .StashCount }}{{ end }}) ", "type": "git" }, { "background": "#86BBD8", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \ue718 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} ", "type": "node" }, { "background": "#33658A", "foreground": "#ffffff", "properties": { "time_format": "15:04" }, "style": "diamond", "template": " \u2665 {{ .CurrentDate | date .Format }} ", "trailing_diamond": "\ue0b0", "type": "time" } ], "type": "prompt" }, { "alignment": "right", "segments": [ { "foreground": "#FFBD00", "style": "diamond", "template": "RAM:{{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1000000000.0) }}/{{ (div .PhysicalTotalMemory 1000000000.0) }}GB ", "trailing_diamond": " ", "type": "sysinfo" }, { "foreground": "#ffffff", "leading_diamond": "\u250b", "properties": { "style": "roundrock", "threshold": 0 }, "style": "diamond", "template": " {{ .FormattedMs }} ", "type": "executiontime" } ], "type": "prompt" }, { "alignment": "left", "newline": true, "segments": [ { "foreground": "#ffffff", "style": "plain", "template": "\u2b9e ", "type": "text" } ], "type": "prompt" } ], "final_space": true, "version": 2 } ```