Windows Terminal 美化

🎉好看是第一生产力

本文包含 Windows Terminal 以及 Powershell 的美化。

主要是因为最近 Surface 送修,回来之和全要重新配置,于是开始陆续整理一些工具的简明使用教程,以便到时快速复原工作环境。

写在前面

先来效果图

PowerShell 美化

安装 oh-my-posh

首先以管理员身份启动 Windows Terminal,新建 powershell 窗口,执行提下命令安装 posh-git

1
Install-Module posh-git -Scope CurrentUser

执行下面的命令安装 oh-my-posh

1
Install-Module oh-my-posh -Scope CurrentUser

新建或打开 powershell 的配置文件

执行$profile查看路径

执行notepad $profile编辑文件

向其中添加以下内容,其中第三行为设置主题

1
2
3
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Avit

使用 $ThemeSettings查看主题存放位置 CurrentThemeLocation,同目录下有其他主题可供选择。

美化 ls 命令

使用 Get-ChildItem 美化ls命令,首先需要安装,在 powershell (管理员身份)执行以下命令

1
Install-Module -AllowClobber Get-ChildItemColor

执行 notepad $profile,将下列内容添加进去

1
2
3
4
5
6
If (-Not (Test-Path Variable:PSise)) {  # Only run this in the console and not in the ISE
    Import-Module Get-ChildItemColor
    
    Set-Alias l Get-ChildItem -option AllScope
    Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
}

Get-ChildItem 还提供了一些个性化的颜色设置,可以参看官方 Github 的 README 说明。

美化ls命令后效果如下

Windows Terminal 美化

打开 Windows Terminal 的 Settings,即 settings.json 文件。

下面配置可供参考,依样画葫芦即可。

其中guid可以用命令生成[Guid]::NewGuid()生成。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// This file was initially generated by Windows Terminal 1.3.2651.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.
            "fontFace": "YaHei Monaco Hybird",
            "cursorShape": "vintage",
            "colorScheme": "Nord",
            "useAcrylic": true,
            "acrylicOpacity": 0.9
        },
        "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": true,
                "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": "Nord",
            "background": "#2e3440",
            "foreground": "#eceff4",
            "brightBlack":  "#3f68b9",
            "brightBlue": "#5e81ac",
            "brightCyan": "#8fbcbb",
            "brightGreen": "#a3be8c",
            "brightPurple": "#b48ead",
            "brightRed": "#bf616a",
            "brightWhite": "#eceff4",
            "brightYellow": "#ebcb8b",
            "black": "#2e3440",
            "blue": "#5e81ac",
            "cyan": "#8fbcbb",
            "green": "#a3be8c",
            "purple": "#b48ead",
            "red": "#bf616a",
            "white": "#eceff4",
            "yellow": "#ebcb8b"
        }
    ],

    // Add custom actions and keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
    "actions":
    [
        // 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" },

        // 自定义
        { "command": "closeTab", "keys": "ctrl+w" },
        { "command": "newTab", "keys": "ctrl+q" },
        // { "command": { "action": "splitPane", "split": "vertical" }, "keys": "alt+shift+=" }, 默认就有了
        // { "command": { "action": "splitPane", "split": "horizontal" }, "keys": "alt+shift+-" }, // 默认就有了
        { "command": "closePane", "keys": "alt+shift+w" } // 默认为ctrl+shift_w
    ]
}
updatedupdated2020-11-232020-11-23
add gitinfo
点击刷新