Windows Terminal 安装配置

在Microsoft Store安装即可。

配置文件

菜单—> 设置,打开settings.json

// 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}",
    "profiles": [
        {
            // Make changes here to the powershell.exe profile
            "background": "#000000",
            "backgroundImage": "C:\\WinTerminal Config\\background.jpg",
            "backgroundImageOpacity": 0.6,
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",
            "colorScheme": "Monokai Remastered",
            "useAcrylic": false,
            "acrylicOpacity": 0.7,
            "closeOnExit": true,
            "acrylicOpacity": 0.25,
            "cursorColor": "#FFFFFF",
            "fontFace": "Delugia Nerd Font",
            "fontFace": "等距更纱黑体 SC",
            "hidden": false,
            "tabTitle": "Powershell",
            "startingDirectory": "."
        },
        {
            // Make changes here to the cmd.exe profile
            "background": "#000000",
            "backgroundImage": "C://1.jpg",
            "backgroundImageOpacity": 0.5,
            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "cmd",
            "commandline": "cmd.exe",
            "colorScheme": "Monokai Remastered",
            "useAcrylic": true,
            "acrylicOpacity": 0.7,
            "closeOnExit": true,
            "acrylicOpacity": 0.25,
            "cursorColor": "#FFFFFF",
            "fontFace": "Delugia Nerd Font",
            "hidden": false
        },
        {
            "background": "#000000",
            "backgroundImage": "C://1.jpg",
            "backgroundImageOpacity": 0.6,
            "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
            "colorScheme": "AdventureTime",
            "useAcrylic": true,
            "acrylicOpacity": 0.7,
            "closeOnExit": true,
            "acrylicOpacity": 0.25,
            "cursorColor": "#FFFFFF",
            "fontFace": "Delugia Nerd Font",
            "hidden": false,
            "name": "Azure Cloud Shell",
            "source": "Windows.Terminal.Azure"
        }
    ],
    // Add custom color schemes to this array
    "schemes": [
        {
            "name": "3024 Day",
            "black": "#090300",
            "red": "#db2d20",
            "green": "#01a252",
            "yellow": "#fded02",
            "blue": "#01a0e4",
            "purple": "#a16a94",
            "cyan": "#b5e4f4",
            "white": "#a5a2a2",
            "brightBlack": "#5c5855",
            "brightRed": "#e8bbd0",
            "brightGreen": "#3a3432",
            "brightYellow": "#4a4543",
            "brightBlue": "#807d7c",
            "brightPurple": "#d6d5d4",
            "brightCyan": "#cdab53",
            "brightWhite": "#f7f7f7",
            "background": "#f7f7f7",
            "foreground": "#4a4543"
        },
        {
            "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": "#1f1d45",
            "foreground": "#f8dcc0"
        },
        {
            "name": "Monokai Remastered",
            "black": "#1a1a1a",
            "red": "#f4005f",
            "green": "#98e024",
            "yellow": "#fd971f",
            "blue": "#9d65ff",
            "purple": "#f4005f",
            "cyan": "#58d1eb",
            "white": "#c4c5b5",
            "brightBlack": "#625e4c",
            "brightRed": "#f4005f",
            "brightGreen": "#98e024",
            "brightYellow": "#e0d561",
            "brightBlue": "#9d65ff",
            "brightPurple": "#f4005f",
            "brightCyan": "#58d1eb",
            "brightWhite": "#f6f6ef",
            "background": "#0c0c0c",
            "foreground": "#d9d9d9"
        },
        {
            "name": "Solarized Darcula",
            "black": "#25292a",
            "red": "#f24840",
            "green": "#629655",
            "yellow": "#b68800",
            "blue": "#2075c7",
            "purple": "#797fd4",
            "cyan": "#15968d",
            "white": "#d2d8d9",
            "brightBlack": "#25292a",
            "brightRed": "#f24840",
            "brightGreen": "#629655",
            "brightYellow": "#b68800",
            "brightBlue": "#2075c7",
            "brightPurple": "#797fd4",
            "brightCyan": "#15968d",
            "brightWhite": "#d2d8d9",
            "background": "#3d3f41",
            "foreground": "#d2d8d9"
        }
    ],
    // Add any keybinding overrides to this array.
    // To unbind a default keybinding, set the command to "unbound"
    "keybindings": []
}
  • 重要配置项说明
// 背景图片及透明度,注意路径中用双斜杠\\
            "backgroundImage": "C:\\WinTerminal Config\\background.jpg",
            "backgroundImageOpacity": 0.6,

// guid,配置profile的标识码,可以有多个配置,在文件开头"defaultProfile"用guid选择
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

// 区分应用的shell:powershell?cmd?
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",

// 颜色主题,在文件下面可以添加多个,在"colorScheme"里选择
            "colorScheme": "Monokai Remastered",

// 毛玻璃半透明特效开关,透明度
            "useAcrylic": false,
            "acrylicOpacity": 0.7,

// 该字体是能适应oh-my-posh的等宽字体
            "fontFace": "等距更纱黑体 SC",

// 添加右键菜单后,配置默认打开路径为当前路径
            "startingDirectory": "."
配色方案

配色方案下载:iTerm2-Color-Schemes

右键菜单项

新建一个.reg文件:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows Terminal here"
"Icon"="C:\\WinTerminal Config\\terminal.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\Architect\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

保存后运行即可。

oh-my-posh安装配置

安装包管理器Chocolatey
# 管理员模式运行powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
安装oh-my-posh
# 管理员模式运行powershell
choco install ConEmu
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser

# 设置profile配置文件
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }

# 配置默认开启oh-my-posh
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

常见故障及排除

权限问题

很多安装失败、无法访问xx路径可能是由于非管理员权限导致,重启terminal使用管理员身份运行。

PowerShell脚本执行权限

PowerShell 脚本 .ps1 有四种执行策略:

  • Restricted —— 默认的设置, 不允许任何 script 运行
  • AllSigned —— 只能运行经过数字证书签名的 script
  • RemoteSigned —— 运行本地的 script 不需要数字签名,但是运行从网络上下载的 script 就必须要有数字签名
  • Unrestricted —— 允许所有的 script 运行

输入下面的命令查看当前执行策略:

get-executionpolicy

而由于 PowerShell 每次打开都是通过一个 .ps1 脚本完成个性化配置的,所以失败很有可能是因为权限不足导致的。

通过下面命令更改执行策略:

Set-ExecutionPolicy [[ 策略名 ]]

调成 RemoteSigned 或者 Unrestricted 均可,建议前者。

之后重启终端就可以正常初始化了。