Windows Termianl 是一款新的Windows 终端软件,不仅从外观、速度上都比 CMD 耐看,好用,而且进过一翻折腾之后,可以实现类似 Linux 系统下的 ZSH + Oh my ZSH 的效果。
效果图

安装 Windows Termianl
推荐从Microsoft Store安装Windows Termianl ,因为通过商店安装方便,而且可自动在商店更新Windows Termianl。
安装 PowerShell
Github仓库地址:https://github.com/PowerShell/PowerShell
预览版和发行版都可以下载,我下载的是发行版,目前版本是v7.1.3 Release of PowerShell
下载地址:https://github.com/PowerShell/PowerShell/releases/
安装 Oh my Posh
Oh my Posh 是一款可以给 Shell 提供主题引擎,类似 Oh my Zsh
官方安装教程:https://ohmyposh.dev/docs/installation
官方升级教程:https://ohmyposh.dev/docs/upgrading
在安装这个引擎之前,还需要安装一个包 Scoop
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json
scoop update oh-my-posh
[下载地址]
配置 Windows Termianl
接下来是重点了,前戏已经准备完成,接下来就是配置了。
按下图打开配置

修改配置
Windows Termianl 是一个 Json 文件
// 不显示之类的信息:https://aka.ms/powershell Type 'help' to get help.
"commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
// 使用上面安装的字体
"fontFace": "MesloLGM NF"- 在当前的数据体里,找到键名为
"guid"的值,复制。替换掉第11行左右的,键名为defaultProfile的值
完成上面操作之后,应该和下图差不多一致,其中guid和defaultProfile的值,每个人电脑不同,具体值也不同,不必和我的一致(好像直接复制粘贴我下面的配置,和我的一致也可以?)
// 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": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", // 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. "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "name": "Windows PowerShell", "commandline": "powershell.exe", "hidden": false }, { // Make changes here to the cmd.exe profile. "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "name": "命令提示符", "commandline": "cmd.exe", "hidden": false }, { "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", "hidden": false, "name": "Azure Cloud Shell", "source": "Windows.Terminal.Azure" }, { "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell", "source": "Windows.Terminal.PowershellCore", // 不显示之类的信息:https://aka.ms/powershell Type 'help' to get help. "commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo", // 字体 "fontFace": "MesloLGM NF" }, { "guid": "{a3a2e83a-884a-5379-baa8-16f193a13b21}", "hidden": false, "name": "PowerShell 7 Preview", "source": "Windows.Terminal.PowershellCore" } ] }, // Add custom color schemes to this array. // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes "schemes": [], // 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" } ] }
修改环境配置
在 Windows Termianl 执行下面命令
notepad.exe $PROFILE
复制粘贴下面代码
Set-PoshPrompt PowerLine Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
说明
设置
Oh my Posh主题为PowerLine按
Table键自动完成按
Ctrl+z键撤销按
↑键找回当前命令之前历史命令按
↓键找回当前命令之后历史命令
最后关闭 Windows Termianl 再打开,效果就和效果图一致了。
修改Oh my Posh主题
修改主题也很简单,重复上个步骤,修改 Set-PoshPrompt 后面的值为对应的主题即可。
执行下面命令,可以查看Oh my Posh有什么主题。
Get-PoshThemes