Windows Terminal 使用教程

安裝

在win10的應(yīng)用商店中搜索windos terminal下載安裝即可。


美化

1. 設(shè)置 Powerline

Powerline 提供自定義的命令提示符體驗(yàn),提供 Git 狀態(tài)顏色編碼和提示符


image.png
  • 必備條件:安裝 Powerline 字體

Powerline 使用字形來設(shè)置提示符樣式。 如果你的字體不包含 Powerline 字形,則在整個提示符中,你可能會看到若干 Unicode 替換字符“&#x25AF”。 盡管 Cascadia Mono 不包括 Powerline 字形,但你可以安裝 Cascadia Code PL 或 Cascadia Mono PL,這兩者包含 Powerline 字形。 可以從 Cascadia Code GitHub 發(fā)布頁安裝這些字體。

使用 PowerShell,執(zhí)行下面的命令分別安裝 Posh-Git 和 Oh-My-Posh:

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

2. 自定義 PowerShell 提示符

使用powershell執(zhí)行下面的命令,新建或打開powershell的配置腳本

notepad $PROFILE

該腳本在每次啟動 PowerShell 時運(yùn)行。 詳細(xì)了解 PowerShell 配置文件。

在 PowerShell 配置腳本中,將以下內(nèi)容添加到文件的末尾:

Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

現(xiàn)在,每個新實(shí)例啟動時都會導(dǎo)入 Posh-Git 和 Oh-My-Posh,然后從 Oh-My-Posh 設(shè)置 Paradox 主題。 Oh-My-Posh 附帶了若干內(nèi)置主題。

上面的腳本執(zhí)行可能會報錯,如果報錯的話,在powershell中執(zhí)行下面的命令即可解決。參考:https://www.cnblogs.com/wswind/p/10911286.html

Set-ExecutionPolicy Unrestricted

3. 在設(shè)置中將 Cascadia Code PL 設(shè)置為 fontFace

若要設(shè)置 Cascadia Code PL 以便與 PowerLine 一起使用(在系統(tǒng)中下載、解壓縮和安裝之后),需要通過從“Windows Terminal”下拉菜單中選擇“設(shè)置”來打開 settings.json 文件中的配置文件設(shè)置。

settings.json 文件打開后,找到 Windows PowerShell 配置文件,并添加 "fontFace": "Cascadia Code PL",將 Cascadia Code PL 指定為字體。 這樣就會顯示很好看的 Cascadia Code Powerline 字形。

Windows PowerShell 配置文件 settings.json 文件現(xiàn)在應(yīng)如下所示:

{
    // 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
},

易用性改造

1. 解決中文亂碼問題

在powershell中執(zhí)行如下命令,打開powershell的配置腳本文件

notepad.exe $PROFILE

在腳本末尾加入如下代碼即可:

$env:LESSCHARSET='utf-8'

2. 添加terminal到右鍵菜單

準(zhǔn)備一個自己喜歡的圖標(biāo)文件
新建一個windowsterminal.reg腳本文件

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\OpenCmdHere]
@="在此處打開命令提示符"
"Icon"="C:\\win10\\icon\\terminal.png"

[HKEY_CLASSES_ROOT\Directory\shell\OpenCmdHere\command]
@="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere]
@="在此處打開命令窗口"
"Icon"="C:\\win10\\icon\\terminal.png"

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere\command]
@="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

[HKEY_CLASSES_ROOT\Drive\shell\OpenCmdHere]
@="在此處打開命令窗口"
"Icon"="C:\\win10\\icon\\terminal.png"

[HKEY_CLASSES_ROOT\Drive\shell\OpenCmdHere\command]
@="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenCmdHere]
@="在此處打開命令窗口"
"Icon"="C:\\win10\\icon\\terminal.png"

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenCmdHere\command]
@="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

保存后雙擊運(yùn)行一下即可。

不過雖然能打開終端,但是路徑并不是當(dāng)前路徑,需要在修改windows terminal配置:
打開 Windows Terminal --> 設(shè)置,給 profiles.defaults 加上這么一句:

"startingDirectory": null

另一種添加到右鍵菜單的方法
新建一個windowsterminal.reg腳本文件

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="open windows terminal"
"Icon"="C:\\Users\\vampi\\Pictures\\icon\\terminal.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="wt.exe -d %V"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\runas]
@="open windows terminal 管理員"
"Icon"="C:\\Users\\vampi\\Pictures\\icon\\terminal.ico"

[HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\runas\command]
@="cmd.exe /k \"wt.exe -d %V&&exit\""

雙擊運(yùn)行即可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容