Windows-Terminal美化以及通过OhMyPosh美化PowerShell
歡迎大家來我的博客逛逛👏:hauhau.cn
通過 Powerline 來自定義 PowerShell,以提供Git狀態提示符,再對 Windows Terminal 美化,得到一個優秀的終端體驗
這里先放出微軟的官方教程:
https://docs.microsoft.com/zh-cn/windows/terminal/tutorials/powerline-setup#set-up-powerline-in-wsl-ubuntu
但是微軟給出的文檔有坑,到本文編寫的時候文檔還沒有進行修改,不妨按照我的步驟來設置
安裝OhMyPosh的字體
如果不安裝字體,最后終端可能會出現亂碼
這里我們需要安裝 Meslo LGM NF 字體,這是 Oh my Posh 官方推薦使用的字體,使用微軟推薦的Cascadia Code PL 和 Cascadia Mono PL 會出現圖標不顯示的問題
Github鏈接:
https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip
網絡不好的可以通過Github的鏡像站來下載
https://hub.fastgit.org/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip
下載后解壓,進入ttf文件夾,選中下圖的ttf文件,分別是常規、粗體、斜體、粗斜體,右鍵進行安裝
安裝完后可以在字體設置中預覽
在PowerShell中安裝Posh-Git和Oh-My-Posh
在執行這一步前,先確保你安裝了git
在這一步中,我們會安裝 Posh-Git 和 Oh-My-Posh:
在PoweShell窗口中,用 Terminal 打開 PowerShell 也行,執行以下命令
Install-Module posh-git -Scope CurrentUser Install-Module oh-my-posh -Scope CurrentUser如果想為全部用戶安裝,使用管理員打開 Terminal 或 PowerShell 執行以下命令
Install-Module posh-git Install-Module oh-my-posh如果出現不受信任的存儲庫,就選擇A
如果需要更新這兩個工具,執行以下命令
Update-Module -Name posh-git Update-Module -Name oh-my-posh要注意的是,全局安裝的模塊需要管理員權限才能進行更新
更新完之后我們要卸載舊版本的模塊
先獲取模塊的版本號,需要記住舊版本的版本號
Get-Module -ListAvailable卸載舊版本的模塊
Uninstall-Module -Name "posh-git" -RequiredVersion "0.7.3" Uninstall-Module -Name "oh-my-posh" -RequiredVersion "3.106.7"最后再確認一下是否卸載成功
自定義PowerShell 提示符
現在當前PowerShell窗口導入posh-git和oh-my-posh
Import-Module posh-git Import-Module oh-my-posh然后我們輸入以下命令來預覽效果
Get-PoshThemes選擇你喜歡的主題,記住他的名稱,我這里選擇honukai主題
輸入這個命令
notepad $PROFILE添加以下內容,在每次打開PowerShell的時候,就會執行里面的命令
Import-Module posh-git Import-Module oh-my-posh Set-PoshPrompt -Theme honukai保存并退出,重新打開PowerShell,你就會看到你選擇的主題了
這里和微軟官方的文檔不同,因為oh-my-posh的新版本使用go來重寫了,指令發生了變化,所以舊的命令是無效的
WindowsTerminal美化
打開Terminal,點擊 Ctrl + , 打開配置文件
這里放出我的配置文件,你也可以自己設置,但是 “fontFace” 這一項一定要設置成 MesloLGM NF 字體,否則會亂碼
"fontFace": "MesloLGM NF",配置文件:
// This file was initially generated by Windows Terminal 1.0.1401.0 // It should still be usable in newer versions, but newer versions might have additional // settings, help text, or changes that you will not see unless you clear this file // and let us generate a new one for you.// To view the default settings, hold "alt" while clicking on the "Settings" button. // For documentation on these settings, see: https://aka.ms/terminal-documentation {"$schema": "https://aka.ms/terminal-profiles-schema","defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",// You can add more global application settings here.// To learn more about global settings, visit https://aka.ms/terminal-global-settings// If enabled, selections are automatically copied to your clipboard."copyOnSelect": false,// If enabled, formatted data is also copied to your clipboard"copyFormatting": false,// A profile specifies a command to execute paired with information about how it should look and feel.// Each one of them will appear in the 'New Tab' dropdown,// and can be invoked from the commandline with `wt.exe -p xxx`// To learn more about profiles, visit https://aka.ms/terminal-profile-settings"profiles": {"defaults": {// Put settings here that you want to apply to all profiles.},"list": [{// Make changes here to the powershell.exe profile."backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg","backgroundImageOpacity": 0.6,"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}","name": "Windows PowerShell","commandline": "powershell.exe","colorScheme": "AdventureTime","useAcrylic": false,"closeOnExit": true,"acrylicOpacity": 0.25,"cursorColor": "#FFFFFF","fontFace": "MesloLGM NF","tabTitle": "Powershell","hidden": false},{// Make changes here to the cmd.exe profile."backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg","backgroundImageOpacity": 0.6,"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}","name": "命令提示符","commandline": "cmd.exe","colorScheme": "AdventureTime","useAcrylic": false,"closeOnExit": true,"acrylicOpacity": 0.25,"cursorColor": "#FFFFFF","fontFace": "MesloLGM NF","hidden": false},{"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg","backgroundImageOpacity": 0.6,"guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}","hidden": false,"name": "Ubuntu-20.04","source": "Windows.Terminal.Wsl","startingDirectory": "//wsl$/Ubuntu-20.04/home/hominsu","colorScheme": "AdventureTime","useAcrylic": false,"closeOnExit": true,"acrylicOpacity": 0.25,"cursorColor": "#FFFFFF","fontFace": "MesloLGM NF"},{"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg","backgroundImageOpacity": 0.6,"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}","hidden": false,"name": "Ubuntu-18.04","source": "Windows.Terminal.Wsl","startingDirectory": "//wsl$/Ubuntu-18.04/home/hominsu","colorScheme": "AdventureTime","useAcrylic": false,"closeOnExit": true,"acrylicOpacity": 0.25,"cursorColor": "#FFFFFF","fontFace": "MesloLGM NF"},{"backgroundImage": "E://WIP-6th-anniversary-wallpaper-dark.jpg","backgroundImageOpacity": 0.6,"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}","colorScheme": "AdventureTime","useAcrylic": false,"closeOnExit": true,"acrylicOpacity": 0.25,"cursorColor": "#FFFFFF","fontFace": "MesloLGM NF","hidden": false,"name": "Azure Cloud Shell","source": "Windows.Terminal.Azure"}]},// Add custom color schemes to this array.// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes"schemes": [{"name": "AdventureTime","black": "#050404","red": "#bd0013","green": "#4ab118","yellow": "#e7741e","blue": "#0f4ac6","purple": "#665993","cyan": "#70a598","white": "#f8dcc0","brightBlack": "#4e7cbf","brightRed": "#fc5f5a","brightGreen": "#9eff6e","brightYellow": "#efc11a","brightBlue": "#1997c6","brightPurple": "#9b5953","brightCyan": "#c8faf4","brightWhite": "#f6f5fb","background": "#000000","foreground": "#f8dcc0"}],// Add custom keybindings to this array.// To unbind a key combination from your defaults.json, set the command to "unbound".// To learn more about keybindings, visit https://aka.ms/terminal-keybindings"keybindings": [// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.// These two lines additionally bind them to Ctrl+C and Ctrl+V.// To learn more about selection, visit https://aka.ms/terminal-selection{"command": {"action": "copy","singleLine": false},"keys": "ctrl+c"},{"command": "paste","keys": "ctrl+v"},// Press Ctrl+Shift+F to open the search box{"command": "find","keys": "ctrl+shift+f"},// Press Alt+Shift+D to open a new pane.// - "split": "auto" makes this pane open in the direction that provides the most surface area.// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.// To learn more about panes, visit https://aka.ms/terminal-panes{"command": {"action": "splitPane","split": "auto","splitMode": "duplicate"},"keys": "alt+shift+d"}] }這是文件中的圖片,這張圖片是某天微軟丟到我的郵箱里的,很好看,就一直用了下去
這里放上鏈接
https://image.hauhau.cn//WIP-6th-anniversary-wallpaper-dark.jpg
https://image.hauhau.cn//WIP-6th-anniversary-wallpaper-light.jpg
到此,我們的美化就基本完成了
總結
以上是生活随笔為你收集整理的Windows-Terminal美化以及通过OhMyPosh美化PowerShell的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: atom对比 vscode_当前主流的跨
- 下一篇: 厦门vr虚拟现实,工地安全教育VR体验,