前言
Windows 終端是一個(gè)面向命令行工具和 shell(如命令提示符友扰、PowerShell 和適用于 Linux 的 Windows 子系統(tǒng) (WSL))用戶(hù)的新式終端應(yīng)用程序仗阅。 它的主要功能包括多個(gè)選項(xiàng)卡蛉谜、窗格签餐、Unicode 和 UTF-8 字符支持哗讥、GPU 加速文本呈現(xiàn)引擎辙芍,還可以用于創(chuàng)建你自己的主題并自定義文本铆帽、顏色咆耿、背景和快捷鍵綁定。
1. 安裝
從 windows store中安裝爹橱,搜索terminal 有兩個(gè)萨螺,一個(gè)microsoft terminal一個(gè)windows terminal preview , 選擇后者。
如果你無(wú)法訪問(wèn) Microsoft Store,GitHub 發(fā)布頁(yè)上發(fā)布有內(nèi)部版本慰技。 如果從 GitHub 安裝椭盏,終端將不會(huì)自動(dòng)更新為新版本。
2. 配置參考
可參考我的配置:
// This file was initially generated by Windows Terminal Preview 1.2.2022.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": "Cascadia Code",
"fontSize": 10,
"useAcrylic": true, //使用背景透明
"acrylicOpacity": 0.8, //背景透明度
"launchMode": "default", //啟動(dòng)大小 default , maximized , fullscreen
"initialPosition": "800,#" //啟動(dòng)位置
},
"list": [
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false,
"startingDirectory": null //默認(rèn)值:"%USERPROFILE%"惹盼,通過(guò)地址欄啟動(dòng)庸汗,輸入 wt 即可打開(kāi)Windows terminal (類(lèi)似cmd)
},
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"startingDirectory": null,
"fontFace": "Cascadia Code PL",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": true,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b7}",
"hidden": false,
"name": "git bash",
"icon": "D:\\Program Files\\Git\\favicon.ico",
"commandline": "D:\\Program Files\\Git\\bin\\bash.exe"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],
// 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"
}
]
}
效果圖:
3. 添加git-bash 命令
在list中添加一個(gè)對(duì)象
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b7}",
"hidden": false,
"name": "git bash",
"icon": "D:\\Program Files\\Git\\favicon.ico",
"commandline": "D:\\Program Files\\Git\\bin\\bash.exe"
}
其中g(shù)uid可用工具生成, icon從官網(wǎng)下載(打開(kāi)git-bash官網(wǎng)后手报,在控制臺(tái)網(wǎng)絡(luò)中可找到favicon.ico),放到適當(dāng)位置蚯舱,引用其位置即可。
commandline
填寫(xiě)已安裝的git下的bash.exe路徑
4. 在powershell中使用git并帶有命令行自動(dòng)補(bǔ)全和漂亮的文本[可選]
[可選內(nèi)容,喜歡折騰的用戶(hù)隨意]
參考:https://docs.microsoft.com/zh-cn/windows/terminal/tutorials/powerline-setup
下載字體并安裝:Cascadia Mono PL 掩蛤, 字體下載:CascadiaPL.ttf枉昏, 下載后直接雙擊字體即可安裝。
使用 PowerShell揍鸟,安裝 Posh-Git 和 Oh-My-Posh:
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
注意此處安裝可能會(huì)失敗兄裂,需要kexuejishu上網(wǎng)
- 使用powershell 啟動(dòng)自動(dòng)加載配置文件
echo $profile
Test-Path $profile
New-Item -Path $profile -Type File –Force
使用echo $profile
檢查.ps1文件是否存在,Test-Path $profile
進(jìn)一步測(cè)試是否存在阳藻,若不存在則用命令新建一個(gè)New-Item -Path $profile -Type File –Force
使用文本編輯器打開(kāi)該 PowerShell 配置文件,該腳本在每次啟動(dòng) PowerShell 時(shí)運(yùn)行晰奖。 詳細(xì)了解 PowerShell 配置文件。
在 PowerShell 配置文件中腥泥,將以下內(nèi)容添加到文件的末尾:
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
現(xiàn)在匾南,每個(gè)新實(shí)例啟動(dòng)時(shí)都會(huì)導(dǎo)入 Posh-Git 和 Oh-My-Posh,然后從 Oh-My-Posh 設(shè)置 Paradox 主題蛔外。 Oh-My-Posh 附帶了若干內(nèi)置主題蛆楞。
效果如下:
- 注意: 如果啟動(dòng)powershell時(shí)報(bào)錯(cuò)如下:
. : 無(wú)法加載文件 C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因?yàn)樵诖讼到y(tǒng)上禁止運(yùn)行腳
本夹厌。有關(guān)詳細(xì)信息豹爹,請(qǐng)參閱 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) []矛纹,PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
則可根據(jù)https:/go.microsoft.com/fwlink/?LinkID=135170中的提示進(jìn)行設(shè)置, 簡(jiǎn)單的方式可這樣操作:
使用管理員權(quán)限打開(kāi)powershell
Get-ExecutionPolicy
# 如果是Restricted, 則代表不能使用本地加載ps1
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# 設(shè)置本地用戶(hù)執(zhí)行策略為 RemoteSigned
完成, 重新打開(kāi)terminal后進(jìn)入powershell可發(fā)現(xiàn)已經(jīng)可以加載ps1文件
5. 將本地cmd命令默認(rèn)使用windows terminal打開(kāi)
快捷鍵win+r
后在打開(kāi)的運(yùn)行窗口輸入cmd
打開(kāi)cmd窗口后在窗口頭部右鍵選擇屬性打開(kāi)屬性對(duì)話框,然后選擇終端,在默認(rèn)終端應(yīng)用程序中選擇Windows Terminal即可,下次打開(kāi)cmd時(shí)自動(dòng)使用Windows Terminal終端打開(kāi)
或者在打開(kāi)的Windows Terminal終端中選擇設(shè)置
6. Windows Terminal啟動(dòng)快捷方式
方法1: win+s
中輸入wt
即可啟動(dòng)Windows Terminal
方法2: win+r
中輸入wt
即可啟動(dòng)Windows Terminal
方法3: 在文件夾路徑上輸入wt
,此命令根目錄為默認(rèn)目錄
方法4: (推薦)在文件夾路徑上輸入'cmd',此時(shí)命令根目錄為當(dāng)前目錄
方法5: (推薦)大多數(shù)編輯器(如:vs,vscode,webstorm,idea等等)都自帶終端,打開(kāi)終端后直接輸入start cmd
也可打開(kāi)終端, 而且終端根目錄也是當(dāng)前自帶終端的根目錄. 方便執(zhí)行帶有當(dāng)前路徑的命令.
總結(jié)
本文從安裝到設(shè)置,再到默認(rèn)切換終端,最后快捷的啟動(dòng)方式,簡(jiǎn)單的帶你進(jìn)入了Windows Terminal的世界, 從此一款高效臂聋、美觀、現(xiàn)代的命令行工具伴隨著我們的日常開(kāi)發(fā)??
本文作者:wwmin
微信公眾號(hào): DotNet技術(shù)說(shuō)
本文鏈接:http://www.reibang.com/p/faeb78aed400
版權(quán)聲明:轉(zhuǎn)載請(qǐng)注明出處或南!
聲援博主:如果您覺(jué)得文章對(duì)您有幫助逻住,關(guān)注點(diǎn)贊, 您的鼓勵(lì)是博主的最大動(dòng)力!