Windows PowerShell 美化
前言
Linux 和 macOS 上的 PowerShell 使用 .NET Core,即 Microsoft Windows 上的完整 .NET Framework 的子集。 這非常重要,因為 PowerShell 提供對基礎(chǔ)框架類型和方法的直接訪問。 因此,在 Windows 上運行的腳本可能無法在非 Windows 平臺上運行,因為框架之間存在差異。
Windows 終端程序是一款新式、快速、高效、強大且高效的終端應(yīng)用程序,適用于命令行工具和命令提示符,PowerShell和 WSL 等 Shell 用戶。主要功能包括多個選項卡、窗格、Unicode、和 UTF-8 字符支持,GPU 加速文本渲染引擎以及自定義主題、樣式和配置。
本文將 .Net Core的PowerShell 用 PowerShell 7 代替
參考:
.NET Framework PowerShell和 .NET Core PowerShell的區(qū)別: https://learn.microsoft.com/zh-cn/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.3
Windows Terminal簡介: https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701?hl=zh-cn&gl=cn
下載并安裝 Windows Terminal(Windows 11直接跳過)
- Github下載
- 使用Windows 10自帶的Microsoft Store也可以下載(建議)
下載并安裝 PowerShell 7
- Github下載 (建議下載msi結(jié)尾的 Windows Installer 安裝包文件,可以安裝到其他盤,不用手動設(shè)置環(huán)境變量。并且可以選擇添加到右鍵菜單。)
- 使用Windows 10自帶的 Microsoft Store 也可以下載 (不用配置Windows Terminal)
改變安裝路徑
將PowerShell 7添加到右鍵菜單,選擇如圖所示的選項
問題
Windows Terminal和安裝的PowerShell 7以管理員運行的時候會出現(xiàn) Windows無法訪問指定設(shè)備、路徑、或文件,你可能沒有適當(dāng)?shù)臋?quán)限訪問該項目。
解決
在C:\Program Files目錄中有個WindowsApps文件夾,該文件夾是隱藏的,需要開啟查看隱藏文件及文件夾的功能,該文件夾是Windows Store下載程序的文件夾,更改文件夾權(quán)限 右鍵該文件夾的屬性–>安全->高級–>更改–>高級–>立即查找–>選擇自己電腦的用戶名–>確定–>勾選替換子容器和對象的所有者–>確定,開啟文件夾的繼承權(quán) 右鍵該文件夾的屬性–>安全–>高級–>啟用繼承
下載并安裝 Oh-My-Posh
- Github下載
- PowerShell命令下載并安裝
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))
參考:https://ohmyposh.dev/docs/installation/windows
下載并安裝 oh-my-posh 需要的字體
- Nerd Fonts (建議下載DejaVuSansMono Nerd Fonts字體)
- PowerLine-Fonts
本文安裝以下兩個字體:
安裝字體直接雙擊打開點擊安裝
配置 Windows Terminal 使用 Powershell 7
Ctrl+, 快捷鍵直接打開設(shè)置
PowerShell 圖標(biāo)鏈接
點擊保存
打卡 Windows Terminal --> 點擊剛才配置的文件 --> 外觀(在其他設(shè)置里,如果窗口小了,可以下滑鼠標(biāo)滾輪,就可以看到了)
設(shè)置主題:
選擇剛才安裝的字體
選擇光標(biāo)形狀
設(shè)置背景圖像(根據(jù)自己的愛好選擇)
點擊保存,就配置好了
配置oh-my-posh
PowerShell中輸入
oh-my-posh init pwsh --config "$env:USERPROFILE\AppData\Local\Programs\oh-my-posh\themes\1_shell.omp.json" | Invoke-Expression
或
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\1_shell.omp.json" | Invoke-Expression
oh-my-posh自帶的主題在:C:\Users\UserName\AppData\Local\Programs\oh-my-posh\themes\
官網(wǎng)顯示的主題樣式和對應(yīng)的主題名:https://ohmyposh.dev/docs/themes
使用 Get-PoshThemes Powershell命令也可以查看對應(yīng)的主題樣式和主題名
配置PowerShell 7環(huán)境變量
if(!(Test-Path -Path $PROFILE)){ New-Item -ItemType file -Path $PROFILE -Force} & notepad $PROFILE
最后在記事本中輸入以下PowerShell命令
選擇自己喜歡的主題,替換下面的主題名
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\主題名.omp.json" | Invoke-Expression
然后輸入以下PowerShell命令,使配置文件立即生效
. $PROFILE
保存退出
展示
配置 PowerShell 7
WIN+R 輸入pwsh進入PowerShell 7–>鼠標(biāo)左鍵點擊左上角的PowerShell圖標(biāo)–>點擊屬性–>字體選擇安裝好的
–>顏色不透明度設(shè)置為90%(根據(jù)自己的喜好設(shè)置)
展示
配置并美化IDEA的 PowerShell 7
-
配置IDEA使用PowerShell 7
文件(File)–>設(shè)置(Settings)–>工具(Tools)–>終端(Terminal)
選擇自己安裝的PowerShell 7
Microsoft Store安裝的在 C:\Users\windy\AppData\Local\Microsoft\WindowsApps\pwsh.exe
Github下載安裝的在安裝時你自己選擇的目錄 -
配置IDEA的PowerShell 7終端字體
Ctrl+Alt+S 快捷鍵打開IDEA設(shè)置(Settings)–>編輯器(Editor)–>配色方案(Color Scheme)–>控制臺字體(Console Font)–>選擇使用控制臺字體,而不是默認(Use console font instead of the default)–>選擇安裝好的字體
展示
配置并美化VsCode的PowerShell 7
-
配置 VsCode 的默認終端
文件(File)–>首選項(Preferences)–>設(shè)置(Settings)–>搜索(Search settings) Profile: Window -->點擊在Settings.json中編輯(Edit in settings.json)
復(fù)制以下json代碼并覆蓋圖中選中的json代碼
"terminal.integrated.profiles.windows": {
"PowerShell 7": {
"path": [
// 安裝PowerShell 7的路徑,粘貼到j(luò)son文件之后,要刪除這行
"D:\\powershell\\7\\pwsh.exe"
],
"args": [
"-NoLogo"
]
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell 7",
Ctrl+S 保存settings.json文章來源:http://www.zghlxwxcb.cn/news/detail-464868.html
參考:https://code.visualstudio.com/docs/terminal/profiles文章來源地址http://www.zghlxwxcb.cn/news/detail-464868.html
-
配置 VsCode 的 PowerShell 7 終端字體
Windows設(shè)置(WIN+I)–>個性化–>字體–>搜索字體名
VsCode設(shè)置中搜索 Editor: Font Family
在其余的字體后加上查看的字體名,字體直接用英文逗號分隔。 注意:字體之間有空格的名稱,要在字體名的兩邊加上英文單引號!)
展示
到了這里,關(guān)于Windows 10 系統(tǒng)PowerShell美化 IDEA終端、VsCode終端以及Windows Terminal的PowerShell的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!