1. 前言
微軟的新終端Windows Terminal終於發佈正式版了。這個終端誕生以來就大獲好評,對於使用Windows進行開發的小夥伴來說又有了新的玩具了。先來看看官方的介紹視頻吧。
接着胖哥教大家如何去美化這個終端,把它打造成時尚的開發利器。
2. 安裝
安裝非常簡單,通過Microsoft Store可以輕鬆安裝Windows Terminal。
3. 安裝美化主題
打開PowerShell安裝Oh-My-Posh[1]和Posh-Git[2]
Set-ExecutionPolicy Bypass
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Posh-Git將Git狀態信息添加到提示,併爲Git命令、參數、遠程和分支名稱添加 tab 自動補全。Oh-My-Posh爲PowerShell提示符提供主題功能。
如果使用的是PowerShell Core,請安裝PSReadline:
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
當然你可以在命令行中執行 Get-Theme
列出所有的樣式:
然後使用Set-Theme 名稱
來預覽你想要的風格,然後替換上面的記事本對應的樣式名稱即可。
4. 安裝 Powerline 字體
Powerline提供自定義的命令提示符體驗,提供Git狀態顏色編碼和提示符,不然很多符號都是亂碼。
推薦到我的Git倉庫下載,地址爲https://gitee.com/felord/fonts,安裝方法參考README,非常簡單。
5. 自定義配置
按照上圖打開配置是一個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 官方文檔[4]
6. 添加 Windows Terminal 到右鍵菜單
將Windows Terminal添加到右鍵菜單也是剛需啊,會讓我們方便很多。這裏告訴你一個最簡單的方法,下載一個腳本右鍵執行安裝就行了。腳本可以通過公衆號:碼農小胖哥 回覆 wint 即可。
文中引用
[1]
Oh-My-Posh: https://github.com/JanDeDobbeleer/oh-my-posh
[2]Posh-Git: https://github.com/dahlbyk/posh-git
[3]Windows Terminal Themes: https://atomcorp.github.io/themes
[4]Windows Terminal官方文檔: https://docs.microsoft.com/zh-cn/windows/terminal/
往期推薦:
第二大JDK項目AdoptOpenJDK 加入Eclipse基金會
2020-06-26
Jib無痛構建Docker鏡像不影響第二天上班
2020-06-25
更多精彩盡在閱讀原文,如果文章對您有用請點個再看和轉發讓更多人看到。