以下記事の元になったノート。 <div class="link-card"> <div class="link-card-header"> <img src="https://avatars1.githubusercontent.com/u/9500018?s=460&v=4" class="link-card-site-icon"/> <span class="link-card-site-name">MAMANのITブログ</span> </div> <div class="link-card-body"> <div class="link-card-content"> <div> <p class="link-card-title">oh-my-poshをv2からv3へ移行してみた</p> </div> <div class="link-card-description"> oh-my-poshをv2からv3へ移行する際、実施したことをまとめました。 </div> </div> <img src="https://blog.mamansoft.net/images/cover/2021-04-11.jpg" class="link-card-image" /> </div> <a href="https://blog.mamansoft.net/2021/04/11/migrate-oh-my-posh-from-v2-to-v3/"></a> </div> ## v3インストール https://ohmyposh.dev/docs/pwsh ```powershell Install-Module oh-my-posh -Scope CurrentUser -Force ``` `--Force`をつけないと以下の警告が表示される。 ```console WARNING: Version '2.0.412' of module 'oh-my-posh' is already installed at 'C:\Users\syoum\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.412'. To install version '3.133.1', run Install-Module and add the -Force parameter, this command will install version '3.133.1' side-by-side with version '2.0.412'. ``` バージョンの確認方法は以下いずれか。 - `Get-Command -CommandType Function -Module oh-my-posh` - `~\Documents\PowerShell\Modules\oh-my-posh`を見る ## Migration [[PowerShell]]を立ち上げると以下のメッセージが表示される。 ```console Hi there! It seems you're using an oh-my-posh V2 cmdlet while running V3. To migrate your current setup to V3, have a look the documentation. https://ohmyposh.dev/docs/upgrading ``` https://ohmyposh.dev/docs/upgrading を見て移行を進める。 ### V3の特徴 - [[Go]]で書かれているためクロスプラットフォーム対応している - 設定が`$ThemeSettings`から`.json`になった ### テーマからjsonファイルを作成 ```powershell Set-PoshPrompt -Theme slimfat Export-PoshTheme -FilePath ~/.oh-my-posh.json ``` 個人的に不要な設定を除外する。 ```json { "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", "blocks": [ { "alignment": "left", "segments": [ { "background": "#2f2f2f", "foreground": "#fafafa", "properties": { "enable_hyperlink": false, "style": "full" }, "style": "diamond", "type": "path" }, { "background": "#2f2f2f", "foreground": "#96E072", "properties": { "ahead_color": "#c42ebd", "behind_color": "#8A4FFF", "branch_icon": " \uE0A0", "color_background": false, "display_stash_count": true, "display_status": true, "display_upstream_icon": true, "local_changes_color": "#ffeb3b", "prefix": "<#7a7a7a> </>", "staging_color": "#ffeb3b", "status_colors_enabled": true, "working_color": "#E84855", "local_staged_icon": " \uF6B9" }, "style": "diamond", "type": "git" }, { "background": "#2f2f2f", "foreground": "#6CA35E", "properties": { "postfix": "<#7a7a7a> </>", "prefix": "  " }, "style": "diamond", "type": "node" }, { "background": "#2f2f2f", "foreground": "#96E072", "properties": { "postfix": "<#7a7a7a> </>", "prefix": "  " }, "style": "diamond", "type": "python" }, { "background": "#2f2f2f", "foreground": "#3891A6", "properties": { "postfix": "<#7a7a7a> </>", "prefix": "  " }, "style": "diamond", "type": "dotnet" }, { "background": "#2f2f2f", "foreground": "#7FD5EA", "properties": { "postfix": "<#7a7a7a> </>", "prefix": " ﳑ" }, "style": "diamond", "type": "go" }, { "background": "#2f2f2f", "foreground": "#9FD356", "properties": { "always_numeric": true, "color_background": false, "display_exit_code": true, "error_color": "#E84855", "prefix": "  " }, "style": "diamond", "type": "exit" }, { "background": "#2f2f2f", "foreground": "#fafafa", "properties": { "postfix": "", "prefix": "", "text": "" }, "style": "diamond", "trailing_diamond": "", "type": "text" } ], "type": "prompt" } ], "console_title": true, "console_title_style": "template", "console_title_template": "{{if .Root}}root :: {{end}}{{.Shell}} :: {{.Folder}}", "final_space": true } ``` ### [[PowerShell]]からテーマを読み込む処理を修正 `$PROFILE`で読み込むテーマを変更。 ```powershell Set-PoshPrompt -Theme ~/.oh-my-posh.json ``` 以下の設定をすべて削除。`Import-Module`なしでいけるのはちょっと不思議。 ```diff # Powerline #----------------------------------------------------- - Import-Module posh-git - Import-Module oh-my-posh Invoke-Expression (& { $hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' } (zoxide init --hook $hook powershell) -join "`n" }) - Set-Theme Powerlevel10k-Lean - - # Prompt - $ThemeSettings.Colors.DriveForegroundColor = "Blue" - # Git - $ThemeSettings.GitSymbols.LocalStagedStatusSymbol = "" - $ThemeSettings.GitSymbols.LocalWorkingStatusSymbol = "" - $ThemeSettings.GitSymbols.BeforeWorkingSymbol = [char]::ConvertFromUtf32(0xf040)+" " - $ThemeSettings.GitSymbols.DelimSymbol = [char]::ConvertFromUtf32(0xf040) - $ThemeSettings.GitSymbols.BranchSymbol = [char]::ConvertFromUtf32(0xf126) - $ThemeSettings.GitSymbols.BranchAheadStatusSymbol = [char]::ConvertFromUtf32(0xf0ee)+" " - $ThemeSettings.GitSymbols.BranchBehindStatusSymbol = [char]::ConvertFromUtf32(0xf0ed)+" " - $ThemeSettings.GitSymbols.BeforeIndexSymbol = [char]::ConvertFromUtf32(0xf6b7)+" " - $ThemeSettings.GitSymbols.BranchIdenticalStatusToSymbol = "" - $ThemeSettings.GitSymbols.BranchUntrackedSymbol = [char]::ConvertFromUtf32(0xf663)+" " + Set-PoshPrompt -Theme ~/.oh-my-posh.json #----------------------------------------------------- # fzf ``` ### アイコンの変更 https://www.nerdfonts.com/cheat-sheet `\ufcd1`表記でも直接`ﳑ`でもOK。