立即安裝Windows終端terminal
Git發(fā)布頁面
發(fā)布地址 https://github.com/microsoft/terminal/releases
應(yīng)用商店
安裝地址 https://aka.ms/terminal
winget
winget install --id=Microsoft.WindowsTerminal -e
如果提示winget : 無法將“winget”項識別為 cmdlet、函數(shù)、腳本文件或可運行程序的名稱。請檢查名稱的拼寫,如果包括路徑,請確保路徑正確,然后再試一次。
如未安裝winget,安裝地址 https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab
如已安裝,可能是因為沒有將winget添加到環(huán)境變量中,可以添加下,或者試試下面這條命令
%LOCALAPPDATA%\Microsoft\WindowsApps\winget install --id=Microsoft.WindowsTerminal -e
安裝 Oh My Posh
安裝前的注意事項
Windows PowerShell 執(zhí)行策略
在執(zhí)行 winget install 命令之前,先查看下,Windows PowerShell 的執(zhí)行策略
執(zhí)行策略 是 Windows PowerShell安全策略中的一部分,它將決定你是否可以載入配置文件(包括你的 Windows PowerShell profile文件)和運行腳本,它將會在運行前確定哪些文件必須具有數(shù)字簽名(digitally signed)
執(zhí)行策略狀態(tài)說明
`Restricted` 表示狀態(tài)是禁止的 不載入配置文件, 不執(zhí)行腳本. Restricted 是默認(rèn)值.
`RemoteSigned` 所有從互聯(lián)網(wǎng)上下載的腳本必須通過信任的出版商簽名(trusted publisher)
`AllSigned` 所有的配置文件和腳本必須通過信任的出版商簽名(trusted publisher),這里所指的腳本頁包括在本地計算機上創(chuàng)建的腳本
`Unrestricted` 載入所有的配置文件和腳本,如果運行了一個從互聯(lián)網(wǎng)上下載且沒有數(shù)字簽名的腳本,在執(zhí)行前都會被提示是否執(zhí)行
// 獲取 Windows PowerShell 當(dāng)前執(zhí)行策略get-ExecutionPolicy
// 修改 Windows PowerShell 中執(zhí)行策略set-ExecutionPolicy RemoteSigned
開始安裝
官網(wǎng)鏈接 https://ohmyposh.dev
發(fā)布頁下載 https://github.com/JanDeDobbeleer/oh-my-posh/releases/
或者終端執(zhí)行命令
// oh-my-posh 安裝命令
winget install JanDeDobbeleer.OhMyPosh
// oh-my-posh 更新命令
winget upgrade JanDeDobbeleer.OhMyPosh
//可在命令后追加-s winget --location D:\OhMyPosh來設(shè)置路徑//如 winget install JanDeDobbeleer.OhMyPosh -s winget --location D:\OhMyPosh
PS:安裝成功后需要重新打開終端,才能繼續(xù)后續(xù)的操作
安裝 Nerd Fonts 字體解決亂碼
Nerd Fonts字體中包含了大量的Icon圖標(biāo)
官網(wǎng)地址 https://www.nerdfonts.com/
releases頁面 https://github.com/ryanoasis/nerd-fonts/releases/tag/v2.3.1
官方推薦使用的是Meslo,我使用的是MesloLGM NF
下載后解壓丟到C:\Windows\Fonts目錄即可完成安裝過
打開 終端->設(shè)置->外觀->字體 進(jìn)行修改
智能補全/智能提示
效果類似于mac的iterm2

PowerShell 7.2 隨 PSReadLine 2.1.0 一起提供。 有較新版本可用。 可以在 Windows PowerShell 5.1 及更新版本上安裝和使用 PSReadLine 的當(dāng)前版本。 對于某些功能,需要運行 PowerShell 7.2 或更高版本。
PSReadLine 為 PowerShell 控制臺提供強大的命令行編輯體驗。 提供以下功能:
命令行的語法著色
語法錯誤的直觀指示
編輯和歷史記錄) (更好的多行體驗
可自定義的鍵綁定
Cmd 和 Emacs 模式
許多配置選項
Bash 樣式完成在 Cmd 模式下 (可選,在 Emacs 模式下默認(rèn))
埃馬克揚克/殺環(huán)
基于 PowerShell 令牌的“word”移動和刪除
預(yù)測 IntelliSense
在控制臺中動態(tài)顯示“幫助”,而不會丟失命令行上的位置
PSReadLine 需要 PowerShell 5.1 或更高版本。 PSReadLine 適用于默認(rèn)的 Windows 控制臺主機、窗口終端和Visual Studio Code。 它在Windows PowerShell ISE 中不起作用。
可以從PowerShell 庫安裝 PSReadLine。 若要在受支持的 PowerShell 版本中安裝 PSReadLine,請運行以下命令。
Install-Module-Name PSReadLine -AllowClobber -Force
預(yù)測 IntelliSense
預(yù)測 IntelliSense 是選項卡完成概念的補充,可幫助用戶成功完成命令。 它使用戶能夠基于用戶歷史記錄和其他特定于域的插件的匹配預(yù)測發(fā)現(xiàn)、編輯和執(zhí)行完整命令。
啟用預(yù)測 IntelliSense
預(yù)測性 IntelliSense 默認(rèn)禁用。 若要啟用預(yù)測,只需運行以下命令:
Set-PSReadLineOption-PredictionSourceHistory
PredictionSource 參數(shù)還可以接受特定于域和自定義要求的插件。
若要禁用預(yù)測 IntelliSense,只需運行:
Set-PSReadLineOption-PredictionSource None
更多配置,可以放在配置文件中,讓其每次都生效
# Shows navigable menu of all options when hitting TabSet-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Autocompletion for arrow keysSet-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
配置文件
終端執(zhí)行
code $PROFILE
首次使用,可能不存在該文件,保存即可
# 去除 Window PowerShell 版權(quán)所有提示
clear
# 配置 oh-my-posh 其中kali為主題名,可以執(zhí)行g(shù)et-Poshthemes獲取主題列表
oh-my-posh init pwsh --config 'C:\Users\Administrator\AppData\Local\Programs\oh-my-posh\themes\kali.omp.json' | Invoke-Expression
# Shows navigable menu of all options when hitting TabSet-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Autocompletion for arrow keysSet-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
自定義命令
您可以在配置文件中寫一些常用的命令來快捷操作,如文章來源:http://www.zghlxwxcb.cn/news/detail-443567.html
# 使用 vscode 打開 $PROFILE 配置文件function vscodeOpen {
Code $PROFILE
}
# 使用 nodepad++ 打開 $PROFILE 配置文件function notepadOpen {
noetepad $PROFILE
}
Git 查看差異和打包差異文章來源地址http://www.zghlxwxcb.cn/news/detail-443567.html
# git
function git-diff ([string]$commitid) {
if ($commitid -eq "")
{
Write-Output "No CommitId"
return
}
git diff $commitid head --stat
}
function git-archive ([string]$commitid) {
if ($commitid -eq "")
{
Write-Output "No CommitId"
return
}
Write-Output "git archive $commitid to C:\Users\Administrator\Desktop\up\export.zip"
git archive -o C:\Users\Administrator\Desktop\up\export.zip head $(git diff --name-only $commitid head)
}
到了這里,關(guān)于記一次配置Windows終端terminal的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!