Windows Terminal

i-fqs發表於2020-10-06

Windows Terminal 自定義

可以在win10商店中搜尋或者 scoop install windows-terminal

Windows Terminal 下拉選單中點選 Settings 進入配置(或使用快捷鍵 Ctrl + ,)
而配置檔案是一個 JSON 格式的檔案,包含以下幾個部分:

  • 全域性配置 Globals:在配置檔案最外側大括號內的內容,會影響整個視窗的配置。如亮/暗主題,預設開啟終端等。
  • 環境配置 Profilesprofiles 內的內容,存放單個環境的配置。這裡可以單獨配置每個在 Windows Terminal 中開啟的終端,如 PowerShell,CMD,Git Bash等。
  • 色彩配置 Schemes:schemes 內的內容,放置終端的主題色彩配置。這些配置可以在環境 Profiles 中被單獨呼叫。
  • 快捷鍵配置 Keybindings:Keybindings 內的內容,適用於終端內的自定義快捷鍵配置

全域性配置 Globals

    "defaultProfile": "{1a7d2b9e-007f-11eb-adc1-0242ac120002}",//想要預設開啟什麼終端改為對應的id即可
    "startingDirectory": "C:\\sync\\doc",//開啟終端的位置

環境配置 Profiles

環境配置包含兩大塊 defaults 和 lists ,分別為所有環境的預設配置、單個環境的特殊配置
這裡可以調整背景配置、字型相關、顏色配置(schemes相關)、游標配置
PowerShell 中輸入 new-guid 就可以新建立一個 UUID(guid)
程式碼插入到 profiles 的 list中

   "list":
        [
            {
                "guid": "{1a7d2b9e-007f-11eb-adc1-0242ac120002}",
                "name": "Git Bash",
                "commandline": "C:\\Program Files\\Git\\bin\\bash.exe",
                "hidden": false, /* 選單欄顯示與否 */
                "icon": "C:\\home\\bin\\win10icon\\02.ico", /* 圖示位置 */
                "backgroundImage": "C:\\home\\bin\\win10icon\\02.ico",//圖片路徑
                "backgroundImageStretchMode": "uniformToFill",//伸縮模式
                "backgroundImageOpacity": 0.1,//圖片背景透明度
                "useAcrylic": true, /* 背景配置開關 */
                "acrylicOpacity": 0.6 /* 透明度 */
            }
...
        ]

配色主題 Schemes

都在shremes

在環境配置中對應環境新增 colorScheme屬性使方案生效

右鍵 -Windows Terminal 新增到右鍵選單,下載terminal.ico,新建一個登錄檔檔案

 Windows Registry Editor Version 5.00
 ​
 [HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
 @="Windows Terminal here"
 "Icon"="圖示位置"
 ​
 [HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
 @="C:\\Users\\name\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

powershell中執行

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck
notepad $PROFILE
# 在 PowerShell 配置檔案中,將以下內容新增到檔案的末尾:
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
{
    // Make changes here to the powershell.exe profile.
    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "name": "Windows PowerShell",
    "commandline": "powershell.exe",
    "fontFace": "Cascadia Code PL",
    "hidden": false
},

WSL Ubuntu 中設定 Powerline

sudo apt install golang-go
go get -u github.com/justjanne/powerline-go
# 自定義 Ubuntu 提示符
nano ~/.bashrc

GOPATH=$HOME/go
function _update_ps1() {
    PS1="$($GOPATH/bin/powerline-go -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

demo

// This file was initially generated by Windows Terminal Preview 1.4.2652.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}", //WPS
    "defaultProfile": "{c91c3170-5b92-4531-885b-9fa3923cb6f2}", //OMV
    // 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.
            // 選擇時複製到剪貼簿
            "copyOnSelect": true,
            // 終端視窗預設大小
            "initialCols": 120,
            "initialRows": 30,
            // "colorScheme": "Flat UI Palette v1 Modified",
            "startingDirectory": "C:\\sync\\doc\\git\\git\\" //,
            //"colorScheme": "Snazzy"// 顏色主題
            // ,"colorScheme": "Campbell"
            // ,"fontFace": "CascadiaCodePL"//字型
        },
        "list": [
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
            /*----WPS----------------------------------------------------------------------------------------------------------------------------------------*/
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "WPS",
                "commandline": "powershell.exe",
                "hidden": false,
                "useAcrylic": true, /* 背景配置開關 */
                "acrylicOpacity": 0.5, /* 透明度 */
                "colorScheme": "WildCherry",
                "fontFace": "Cascadia Code PL"
                // "cursorColor": "#000000",
                // "backgroundImage": "C:\\sync\\doc\\ico\\WPS.png",
                // "backgroundImageStretchMode": "uniformToFill",
                // "backgroundImageOpacity": 0.4
                // // {
                //     "acrylicOpacity": 0.7,
                //     "colorScheme": "Frost",
                //     "cursorColor": "#000000",
                //     "fontFace": "Cascadia Code PL",
                //     "useAcrylic": true
                // }
            },
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
            /*---GIT---------------------------------------------------------------------------------------------------------------------------------------*/
            {
                "guid": "{1a7d2b9e-007f-11eb-adc1-0242ac120002}",
                "name": "Git",
                "commandline": "C:\\Program Files\\Git\\bin\\bash.exe",
                "hidden": false, /* 選單欄顯示與否 */
                "useAcrylic": true, /* 背景配置開關 */
                "acrylicOpacity": 0.5, /* 透明度 */
                "colorScheme": "WildCherry",
                "fontFace": "Cascadia Code PL",
                "cursorColor": "#000000",
                "icon": "C:\\sync\\doc\\repo\\images\\ico\\git.ico" /* 圖示位置 */
            },
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
            /*-----PVE--------------------------------------------------------------------------------------------------------------------------------------*/
            {
                "guid": "{957b369e-ca1d-447e-b565-8b0ce2629f50}",
                "name": "PVE",
                //指定起始目錄 `-t `標誌強制執行偽終端分配。 這可用於在遠端計算機上執行任意基於螢幕的程式
                // "commandline": "ssh -t root@10.1.1.1 \"cd /data/ && exec zsh -l\"",
                "commandline": "ssh root@10.1.1.1",
                "icon": "C:\\sync\\doc\\repo\\images\\ico\\omv.ico", /* 圖示位置 */
                "fontFace": "Cascadia Code PL",
                "hidden": false,
                "colorScheme": "WildCherry",
                "useAcrylic": false,
                "acrylicOpacity": 0.8,
                "padding": "10,10,10,10"
            },
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
     
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
            /*-----WSL_DEBIAN--------------------------------------------------------------------------------------------------------------------------------------*/
            {
                "guid": "{20ea6bc1-0c2b-41b9-a747-5b8c4208bf1c}",
                "name": "WSL_DEBIAN",
                "commandline": "ssh root@127.0.0.1",
                "icon": "C:\\sync\\doc\\repo\\images\\ico\\debian.ico", /* 圖示位置 */
                "hidden": false
            },
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
          
            /*-----WSL--------------------------------------------------------------------------------------------------------------------------------------*/
            {
                "guid": "{58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530}",
                "hidden": false,
                "name": "WSL",
                "source": "Windows.Terminal.Wsl",
                "fontFace": "Cascadia Code PL",
                "colorScheme": "WildCherry",
                "useAcrylic": false,
                "acrylicOpacity": 0.8,
                "padding": "10,10,10,10"
            },
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
            /*------CMD-------------------------------------------------------------------------------------------------------------------------------------*/
            {
                // Make changes here to the cmd.exe profile.
                //CMD
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "name": "CMD",
                "commandline": "cmd.exe",
                "hidden": false
            },
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": true,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530}",
                "hidden": false,
                "name": "Debian",
                "source": "Windows.Terminal.Wsl"
            }
            /*----------------------------------------------------------------------------------------------------------------------------------------------*/
        ]
    },
    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [
        {
            "name": "qs",
            "black": "#1e1e1e",
            "red": "#ff453a",
            "green": "#32d74b",
            "yellow": "#ffd60a",
            "blue": "#0a84ff",
            "purple": "#bf5af2",
            "cyan": "#5ac8fa",
            "white": "#ffffff",
            "brightBlack": "#1e1e1e",
            "brightRed": "#ff453a",
            "brightGreen": "#32d74b",
            "brightYellow": "#ffd60a",
            "brightBlue": "#0a84ff",
            "brightPurple": "#bf5af2",
            "brightCyan": "#5ac8fa",
            "brightWhite": "#ffffff",
            "background": "#1e1e1e",
            "foreground": "#ffffff"
        },
        {
            "name": "midnight-in-mojave",
            "black": "#1e1e1e",
            "red": "#ff453a",
            "green": "#32d74b",
            "yellow": "#ffd60a",
            "blue": "#0a84ff",
            "purple": "#bf5af2",
            "cyan": "#5ac8fa",
            "white": "#ffffff",
            "brightBlack": "#1e1e1e",
            "brightRed": "#ff453a",
            "brightGreen": "#32d74b",
            "brightYellow": "#ffd60a",
            "brightBlue": "#0a84ff",
            "brightPurple": "#bf5af2",
            "brightCyan": "#5ac8fa",
            "brightWhite": "#ffffff",
            "background": "#1e1e1e",
            "foreground": "#ffffff"
        },
        {
            "name": "WildCherry",
            "black": "#000507",
            "red": "#d94085",
            "green": "#2ab250",
            "yellow": "#ffd16f",
            "blue": "#883cdc",
            "purple": "#ececec",
            "cyan": "#c1b8b7",
            "white": "#fff8de",
            "brightBlack": "#009cc9",
            "brightRed": "#da6bac",
            "brightGreen": "#f4dca5",
            "brightYellow": "#eac066",
            "brightBlue": "#308cba",
            "brightPurple": "#ae636b",
            "brightCyan": "#ff919d",
            "brightWhite": "#e4838d",
            "background": "#1f1726",
            "foreground": "#dafaff"
        }
    ],
    // 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": "closePane",
            "keys": "ctrl+w"
        },
        //copy
        {
            "command": {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        //paste
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        // 拆分窗格
        // In settings.json
        {
            "command": {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        },
        // In defaults.json
        {
            "command": {
                "action": "splitPane",
                "split": "horizontal"
            },
            "keys": "alt+shift+-"
        },
        {
            "command": {
                "action": "splitPane",
                "split": "vertical"
            },
            "keys": "alt+shift+plus"
        }
        /*----------------------------------------------------------------------------------------------------------------------------------------------------------*/
        // 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"
            // 
        }
    ]
}


相關文章