[环境配置]Windows Terminal美化

1,403 阅读2分钟

前言

在实际使用过程中,作者并不重度使用shell,也就敲敲一般的命令行,作为一名资深的Windows用户早就习(深)惯(陷)GUI 的方(泥)便(潭)。但就算再怎么偶尔使用命令行,都希望每次都是精致的体验,没错,是Windows Terminal的颜值吸引了我。

准备

  • Windows TerminalMicrosoft Store中下载安装
  • PowerShell 7 这里下载最新版msi直接安装
  • Fira Code Nerd Font 这里下载安装字体

美化

oh-my-posh

oh-my-posh是一款shell的主题引擎,内置了多个好看的主题

powershell中安装,

Install-Module oh-my-posh -Scope CurrentUser
复制代码

查看所有内置主题,

Get-PoshThemes
复制代码

选择一款主题,

Set-PoshPrompt -Theme ys
复制代码

但是这样设置只是一次性的,想要每次打开powershell都使用选中的主题需要打开profile进行设置,

notepad $Profile
复制代码

profile中添加下面的命令然后保存

# 引入 oh-my-posh
Import-Module oh-my-posh

# 设置 PowerShell 主题
Set-PoshPrompt -Theme ys
复制代码

PSReadline

PSReadlinepowershell的增强工具,更加方便的操作命令行

powershell中安装,

Install-Module PSReadline -Scope CurrentUser
复制代码

打开profile进行配置

notepad $Profile
复制代码

添加下面的命令然后保存

# 引入 ps-read-line
Import-Module PSReadLine

# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History

# 每次回溯输入历史,光标定位于输入内容末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

# 设置 Tab 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
复制代码

Windows Terminal设置

打开Windows Terminal -> 设置 -> 打开JSON文件,找到schemes节点,新增一个颜色主题Gruvbox Dark更多主题

"schemes": [
    ......
    {
        "background": "#1E1E1E",
        "black": "#1E1E1E",
        "blue": "#377375",
        "brightBlack": "#7F7061",
        "brightBlue": "#719586",
        "brightCyan": "#7DB669",
        "brightGreen": "#AAB01E",
        "brightPurple": "#C77089",
        "brightRed": "#F73028",
        "brightWhite": "#E6D4A3",
        "brightYellow": "#F7B125",
        "cursorColor": "#E6D4A3",
        "cyan": "#578E57",
        "foreground": "#E6D4A3",
        "green": "#868715",
        "name": "Gruvbox Dark",
        "purple": "#A04B73",
        "red": "#BE0F17",
        "selectionBackground": "#E6D4A3",
        "white": "#978771",
        "yellow": "#CC881A"
    }
]
复制代码

设置powershell的颜色主题,字体,背景图片,毛玻璃效果等,找到profiles节点下面的PowerShell

"profiles": {
    "defaults": {},
    "list": [
        ......
        {
            "acrylicOpacity": 0.5,
            "backgroundImage": "C:\Users\SeanS\Pictures\Background\win10_purple.png",
            "backgroundImageOpacity": 0.3,
            "backgroundImageStretchMode": "uniformToFill",
            "colorScheme": "Gruvbox Dark",
            "cursorColor": "#FFFFFF",
            "cursorShape": "underscore",
            "fontFace": "FiraCode Nerd Font",
            "fontSize": 12,
            "fontWeight": "normal",
            "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
            "hidden": false,
            "name": "PowerShell",
            "source": "Windows.Terminal.PowershellCore"
        }
        ......
    ]
}
复制代码

最终效果,

image-20210926220503904

总结

简单美化,摆脱了原来powershell蓝白的枯燥,希望能把shell多多用起来