Powershell 美化和 Win 包管理工具
- 2019 年 12 月 4 日
- 筆記
Powershell 用起來的實際體驗其實還是非常優秀的,特別是在 Linux 使用多了之後,再回到win 上來,總是習慣性的開啟 PowerShell 來執行一些指令進行操作。 然而 Powershell 的藍底白字未免有些不太養眼,於是在王少找到了 『oh-my-posh』 的美化插件。 該插件可以使用 Chocolatey 來安裝,於是順帶說說 Chocolatey 這個win 下的包管理工具。
安裝 Chocolatey
Chocolatey is a package manager for Windows (like apt-get or yum but for Windows). It was designed to be a decentralized framework for quickly installing applications and tools that you need. It is built on the NuGet infrastructure currently using PowerShell as its focus for delivering packages from the distros to your door, err computer. Chocolatey是Windows的軟件包管理器(如apt-get或yum,但適用於Windows)。 它被設計為一個分散的框架,用於快速安裝所需的應用程序和工具。 它建立在NuGet基礎設施上,主要使用在PowerShell中。
PowerShell 安裝 Chocolatey 非常簡單,管理員運行,然後輸入如下指令
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
安裝 ConEmu 優化使用體驗
ConEmu-Maximus5 aims to be handy, comprehensive, fast and reliable terminal window where you may host any console application developed either for WinAPI (cmd, powershell, far) or Unix PTY (cygwin, msys, wsl bash). ConEmu-Maximus5旨在提供方便,全面,快速和可靠的終端窗口,您可以在其中託管為WinAPI(cmd,powershell,far)或Unix PTY(cygwin,msys,wsl bash)開發的任何控制台應用程序。
藉助剛才安裝的 Chocolatey 來安裝 Conemu
choco install ConEmu
安裝美化插件
安裝 posh-git 和 oh-my-posh:
Install-Module posh-git -Scope CurrentUser Install-Module oh-my-posh -Scope CurrentUser
如果在PS Core上運行此功能,請確保已經安裝PSReadLine的2.0.0-beta1版本
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
請編輯PowerShell配置文件,啟用:
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force } notepad $PROFILE
將以下行附加到PowerShell配置文件:
Import-Module posh-git Import-Module oh-my-posh Set-Theme Paradox
錯誤提示
系統提示無法運行腳本:
參考 MSDN 解決辦法 – https://docs.microsoft.com/zh-cn/previous-versions/windows/powershell-scripting/hh847748(v=wps.640)
因此,需要把 about_Execution_Policies 的策略調整為 UNRESTRICTED 或更低
在管理員模式下運行 Powershell ,使用如下指令:
Set-ExecutionPolicy -ExecutionPolicy UNRESTRICTED
樣式優化
更多樣式優化和其他內容,可以參閱作者 Github 頁面