手摸手教你美化微軟的新終端Windows Terminal

1. 前言

微軟的新終端Windows Terminal終於發佈正式版了。這個終端誕生以來就大獲好評,對於使用Windows進行開發的小夥伴來講又有了新的玩具了。先來看看官方的介紹視頻吧。git

接着胖哥教你們如何去美化這個終端,把它打形成時尚的開發利器。web

2. 安裝

安裝很是簡單,經過Microsoft Store能夠輕鬆安裝Windows Terminal面試

Microsoft Store 安裝 Windows Terminal

3. 安裝美化主題

打開PowerShell安裝Oh-My-Posh[1]Posh-Git[2]sql

Set-ExecutionPolicy Bypass
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser

Posh-GitGit狀態信息添加到提示,併爲Git命令、參數、遠程和分支名稱添加 tab 自動補全。Oh-My-PoshPowerShell提示符提供主題功能。shell

若是使用的是PowerShell Core,請安裝PSReadlinejson

Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

而後PowerShell命令行執行:數組

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE

會打開以下記事本,將下面的代碼配置到記事本中保存:緩存

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
配置PowerShell

固然你能夠在命令行中執行 Get-Theme 列出全部的樣式:微信

列出全部樣式

而後使用Set-Theme 名稱來預覽你想要的風格,而後替換上面的記事本對應的樣式名稱便可。app

4. 安裝 Powerline 字體

Powerline提供自定義的命令提示符體驗,提供Git狀態顏色編碼和提示符,否則不少符號都是亂碼。

Windows 終端 Powerline PowerShell

推薦到個人Git倉庫下載,地址爲https://gitee.com/felord/fonts,安裝方法參考README,很是簡單。

5. 自定義配置

打開Windows Terminal 配置

按照上圖打開配置是一個json文件,這裏我貼一下個人配置,你抄就是了:

{
    "$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.
            "colorScheme""Banana Blueberry",
            "background""#191323", //背景顏色,PS默認爲藍色
            "closeOnExit"true, //關閉窗口的時候退出全部掛載的程序
            "commandline""powershell.exe", //此處終端打開PS
            "cursorColor""#FFFFFF", //光標顏色
            "cursorShape""bar", //光標形狀(默認爲bar,即條狀)
            "fontFace""DejaVu Sans Mono for Powerline",
            "fontSize"12,
            "guid""{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", //惟一標識符,隨機生成
            "historySize"9001, //緩存大小
            "icon""ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png", //圖標
            "name""PowerShell", //在下拉菜單裏顯示的名稱
            "tabTitle""PowerShell", //在選項卡上顯示的名稱
            "padding""0, 0, 0, 0", //內容的邊框距,默認填充所有空間
            "snapOnInput"true, //輸入的時候自動滾動到輸入位置
            "startingDirectory""%USERPROFILE%" //初始工做目錄,默認爲用戶目錄
        },
        "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"
            }
        ]
    },
    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [
        {
            "name""Monokai Night",
            "background""#1f1f1f",
            "foreground""#f8f8f8",
            "black""#1f1f1f",
            "blue""#6699df",
            "cyan""#e69f66",
            "green""#a6e22e",
            "purple""#ae81ff",
            "red""#f92672",
            "white""#f8f8f2",
            "yellow""#e6db74",
            "brightBlack""#75715e",
            "brightBlue""#66d9ef",
            "brightCyan""#e69f66",
            "brightGreen""#a6e22e",
            "brightPurple""#ae81ff",
            "brightRed""#f92672",
            "brightWhite""#f8f8f2",
            "brightYellow""#e6db74"
        },
        {
            "name""Banana Blueberry",
            "black""#17141f",
            "red""#ff6b7f",
            "green""#00bd9c",
            "yellow""#e6c62f",
            "blue""#22e8df",
            "purple""#dc396a",
            "cyan""#56b6c2",
            "white""#f1f1f1",
            "brightBlack""#495162",
            "brightRed""#fe9ea1",
            "brightGreen""#98c379",
            "brightYellow""#f9e46b",
            "brightBlue""#91fff4",
            "brightPurple""#da70d6",
            "brightCyan""#bcf3ff",
            "brightWhite""#ffffff",
            "background""#191323",
            "foreground""#cccccc"
        }
    ],
    // 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"
        }
    ]
}

若是你想修改字體找到fontFace配置Powerline字體;若是你要修改配色方案,找到schemes數組後將配色方案添加進去便可,激活參考上面的配置將 schemes[i].name的值填寫到profiles.defaults.colorScheme保存重啓終端便可。

這裏推薦一個Windows Terminal配色方案的Github項目Windows Terminal Themes[3]

Windows Terminal Themes

其它什麼透明、毛玻璃、背景圖的操做,網上有不少教程,過於簡單這裏就不提了。更多的配置可參考Windows Terminal 官方文檔[4]

6. 添加 Windows Terminal 到右鍵菜單

Windows Terminal添加到右鍵菜單

Windows Terminal添加到右鍵菜單也是剛需啊,會讓咱們方便不少。這裏告訴你一個最簡單的方法,下載一個腳本右鍵執行安裝就好了


CountDownLatch和CyclicBarrier 傻傻的分不清?超長精美圖文又來了

2020-06-29

大廠面試官必問的Mysql鎖機制

2020-06-29

搞定ReentrantReadWriteLock 幾道小小數學題就夠了

2020-06-22




本文分享自微信公衆號 - 日拱一兵(gh_6235a38420b9)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。

相關文章
相關標籤/搜索